Rules can act as functions, which can be called from both a pattern block and an action block. You can pass values to rules in ASL and receive values back by using the return statement, as described in “Returning values” on page 92. The syntax is as follows:
RULE(<variablename>)
The argument of a rule is a local variable.
The following script reads and counts the words in a file. The READWORD rule is passed an argument that is used as a counter. The count variable behaves as a local variable.
ASL Script (rule_arg.asl): START { READWORD(1) } READWORD(count) { local y = "end"; y:word READWORD(count+1)|eol } do { print(y." ".count); } Input (rule_arg.txt) dog cat goat Output: $ sm_adapter --file=rule_arg.txt rule_arg.asl end 4 goat 3 cat 2 dog 1 $