LAMBDA LISTS


There are several forms in XLISP that require that a "lambda list" be specified. A lambda list is a definition of the arguments accepted by a function. There are four different types of arguments.

The lambda list starts with required arguments. Required arguments must be specified in every call to the function.

The required arguments are followed by the &optional arguments. Optional arguments may be provided or omitted in a call. An initialization expression may be specified to provide a default value for an &optional argument if it is omitted from a call. If no initialization expression is specified, an omitted argument is initialized to NIL. It is also possible to provide the name of a 'supplied-p' variable that can be used to determine if a call provided a value for the argument or if the initialization expression was used. If specified, the supplied-p variable will be bound to T if a value was specified in the call and NIL if the default value was used.

The &optional arguments are followed by the &rest argument. The &rest argument gets bound to the remainder of the argument list after the required and &optional arguments have been removed.

The &rest argument is followed by the &key arguments. When a keyword argument is passed to a function, a pair of values appears in the argument list. The first expression in the pair should evaluate to a keyword symbol (a symbol that begins with a ':'). The value of the second expression is the value of the keyword argument. Like &optional arguments, &key arguments can have initialization expressions and supplied-p variables. It is possible to specify the keyword to be used in a function call. If no keyword is specified, the keyword obtained by adding a ':' to the beginning of the keyword argument symbol is used. In other words, if the keyword argument symbol is 'foo', the keyword will be ':foo'.

If identical keywords occur, those after the first are ignored. Extra keywords will signal an error unless &allow-other-keys is present, in which case the extra keywords are ignored. Also, if the keyword :allow-other-keys is used in the function/macro call, and has a non-nil value, then additional keys will be ignored.

The &key arguments are followed by the &aux variables. These are local variables that are bound during the evaluation of the function body. It is possible to have initialization expressions for the &aux variables.

Here is the complete syntax for lambda lists:

(<rarg>...
	[&optional [<oarg> | (<oarg> [<init> [<svar>]])]...]
	[&rest <rarg>]
	[&key
	[<karg> | ([<karg> | (<key> <karg>)] [<init> [<svar>]])]
	 ... [&allow-other-keys]]
	[&aux [<aux> | (<aux> [<init>])]...])

where:

<rarg>
is a required argument symbol
<oarg>
is an &optional argument symbol
<rarg>
is the &rest argument symbol
<karg>
is a &key argument symbol
<key>
is a keyword symbol (starts with ':')
<aux>
is an auxiliary variable symbol
<init>
is an initialization expression
<svar>
is a supplied-p variable symbol

XLISP-PLUS - Version 2.1g - Tom Almy tom.almy@tek.com - 18 JUL 94
Generated with
WebMaker