XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next

9  Lambda Lists


  1. Arguments
  2. Syntax for Lambda Lists

9.1  Arguments


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.

Required Arguments

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

Optional Arguments

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.

Rest Arguments

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.

Keyword Arguments

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 colon ':']. 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. In addition, 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 colon ':' 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

Auxiliary Variables

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.

  Back to Top


9.2  Syntax for Lambda Lists


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
aux   -   is an auxiliary variable symbol
init   -   is an initialization expression
svar   -   is a supplied-p variable symbol

  Back to Top


XLISP > XLISP 2.0  -  Contents  -  Reference  -  Previous | Next