arglist
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | arglist [2007/02/27 06:02] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Argument Lists======= | ||
+ | Argument lists are an optional way to automatically shift values from | ||
+ | $* into local variables. | ||
+ | or your [[on]]s. | ||
+ | |||
+ | =====Behavior of Argument Lists====== | ||
+ | When an alias or on is called, the magic variable $* is set with the | ||
+ | arguments passed into your code. Usually the first thing most people | ||
+ | do is copy arguments from $* into local variables, such as: | ||
+ | |||
+ | alias oofda { | ||
+ | local var1 $0; | ||
+ | local var2 $1; | ||
+ | local var3 $2-; | ||
+ | echo $var1 and $var2 and $var3!; | ||
+ | }; | ||
+ | |||
+ | But wouldn' | ||
+ | assign the values for you? Argument lists are how you do this | ||
+ | |||
+ | alias oofda (var1, var2, var3) { | ||
+ | echo $var1 and $var2 and $var3!; | ||
+ | }; | ||
+ | |||
+ | or for [[on]]s, | ||
+ | |||
+ | on ^join * (nick, chan, userhost, extra) { | ||
+ | xecho -b $nick!$userhost has joined $chan $extra; | ||
+ | }; | ||
+ | |||
+ | Ordinarily, the whole of $* is put into the arguments; anything left in | ||
+ | $* is put into the final variable. | ||
+ | in an alias or on that uses argument lists. | ||
+ | |||
+ | =====Syntax of Argument Lists===== | ||
+ | An argument list is a comma separated list of terms, surrounded in | ||
+ | parenthesis. | ||
+ | of words specification, | ||
+ | must be either a regular variable term, or the literal string " | ||
+ | or the literal string " | ||
+ | |||
+ | ^ Syntax | ||
+ | | // | ||
+ | | //varname// words //N// | Assign the next //N// words to $varname | ||
+ | | //varname// uwords //N// | Assign the next //N// uwords to $varname | ||
+ | | //varname// qwords //N// | Assign the next //N// qwords to $varname | ||
+ | | //varname// dwords //N// | Assign the next //N// dwords to $varname | ||
+ | | //varname// default "// | ||
+ | | ... | (Final argument only) The remainder of the arguments (if any) should be assigned to the $* magic expando.| | ||
+ | | void | (Final argument only) The remainder of the arguments (if any) should be discarded.| | ||
+ | |||
+ | * The default word-specification is "words 1" | ||
+ | * The default default-value is the empty string ("" | ||
+ | * If you don't provide any argument list, (...) is the default. | ||
+ | |||
+ | ^ Word Type ^ Definition ^ | ||
+ | | words | | | ||
+ | | uwords | | | ||
+ | | qwords | | | ||
+ | | dwords | | | ||
+ | |||
+ | |||
+ | =====Semantics of Argument Lists===== | ||
+ | When you call an alias that has an argument list, each term of the argument | ||
+ | list is created as a local variable, and its initial value is set to $0 (or | ||
+ | however many words you specified), and those word(s) are removed from $*. | ||
+ | |||
+ | If $* runs out before the argument list does, then any remaining arguments | ||
+ | receive their default values (including the default-default value of "" | ||
+ | |||
+ | The last argument in the list is either a variable, the literal string ' | ||
+ | or the literal string ' | ||
+ | variable, kept in $*, or discarded entirely, respectively. | ||
+ | |||
+ | Naturally, argument lists change $*, and there is no way to recover the | ||
+ | original value of $* in an alias (or on) that uses arglists. | ||
+ | |||
+ | ======History: | ||
+ | |||
arglist.txt · Last modified: 2007/02/27 06:02 by 127.0.0.1