[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
5.1 DSSSL formal argument lists
DSSSL formal argument lists are defined by the following grammar:
<formal-argument-list> → <required-formal-argument>* [(#!optional
<optional-formal-argument>*)
] [(#!rest
<rest-formal-argument>)
] [(#!key
<key-formal-argument>*)
(#!rest
<rest-formal-argument>?)
] <required-formal-argument> → <ieee-ident> <optional-formal-argument> → <ieee-ident> |(
<ieee-ident> <initializer>)
<rest-formal-argument> → <ieee-ident> <key-formal-argument> → <ieee-ident> |(
<ieee-ident> <initializer>)
<initializer> → <expr>
When a procedure is applied to a list of actual arguments, the formal and actual arguments are processed from left to right as follows:
- Variables in required-formal-arguments are bound to successive actual arguments starting with the first actual argument. It shall be an error if there are fewer actual arguments than required-formal-arguments.
- Next, variables in optional-formal-arguments are bound to
any remaining actual arguments. If there are fewer remaining actual arguments
than optional-formal-arguments, then variables are bound to the
result of the evaluation of initializer, if one was specified, and
otherwise to
#f
. The initializer is evaluated in an environment in which all previous optional formal arguments have been bound. - If there is a rest-formal-argument, then it is bound to a list of all remaining actual arguments. The remaining actual arguments are also eligible to be bound to keyword-formal-arguments. If there is no rest-formal-argument and there are no keyword-formal-arguments, the it shall be an error if there are any remaining actual arguments.
- If
#!key
was specified in the formal-argument-list, there shall be an even number of remaining actual arguments. These are interpreted as a series of pairs, where the first member of each pair is a keyword specifying the argument name, and the second is the corresponding value. It shall be an error if the first member of a pair is not a keyword. It shall be an error if the argument name is not the same as a variable in a keyword-formal-argument, unless there is a rest-formal-argument. If the same argument name occurs more than once in the list of actual arguments, then the first value is used. If there is no actual argument for a particular keyword-formal-argument, then the variable is bound to the result of evaluating initializer if one was specified, and otherwise#f
. The initializer is evaluated in an environment in which all previous formal key arguments have been bound. - If
#!rest
was specified in the formal-argument-list after a#!key
formal parameter, it is bound to the list of optional non-keyword arguments.
It shall be an error for an <ieee-ident> to appear more than once in a formal-argument-list.
Example:
((lambda (x y) x) 3 4 5 6) ⇒(3 4 5 6) ((lambda (x y #!rest z) z) 3 4 5 6) ⇒ (5 6) ((lambda (x y #!optional z #!rest r #!key i (j 1)) (list x y z i: i j: j)) 3 4 5 i: 6 i: 7) ⇒ (3 4 5 i: 6 j: 1) ((lambda (x y #!optional z #!key i (j 1) #!rest r) (list x y z i: i j: j r)) 3 4 5 i: 6 i: 7 8 9) ⇒ (3 4 5 i: 6 j: 1 (8 9))
[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated on March 31, 2014 using texi2html 5.0.