Concept:ExtendedLambdaList

How to specify optional and/or named arguments

Original Scheme's handling of variable number arguments via dotted-list in formals has its own beauty---it is naturally understood that argument binding in terms of (limited) pattern matching. And you can add optional/named arguments on top of that, by parsing 'rest' arguments by yourself (see let-optionals* and let-keywords*, for example). However, in production code where you write lots of functions with such arguments, it tends to be clumsy.

There are several extensions that allow you to directly express optional/named arguments in the 'formals' position of the lambda form.

SRFI-89

Using lambda*, optional positional arguments, required named arguments and optional named arguments can be specified as followings:

  • optional positional argument: (<variable> <expression>)
  • required named argument: (<keyword> <variable>)
  • optional named argument: (<keyword> <variable> <expression>)

It appears that there's no way to allow arbitrary keyword arguments while specifying some of them (a la &allow-other-keys semantics in CL).

Guile

Using lambda*, optional positional arguments and optional named arguments can be specified in CL way, except Guile uses #:optional, #:key, and #:rest to delimit these parameters in the formals.

It can also accept #:allow-other-keys.

Chicken, Kawa, DSSSL?

The lambda syntax is extended to accept optional positional and named arguments in CL way, except using #!optional, #!key, and #!rest to delimit these parameters.

It doesn't appear to have &allow-other-keys equivalent.

STklos

The lambda syntax is extended to accept optional positional and named arguments in CL way, except using :optional, :key, and :rest to delimit these parameters.

In optional and named arguments you can specify guard predicate as well, in the form:

  (<var> <expression> <guard>)

When the procedure is called, the value of the argument that is a candidate of matching this parameter <var> is first passed to <guard>, and bound to <var> only iff <guard> returns a true value; otherwise, the value of <expression> is used as if the argument is not supplied.