Previous: lambda* Reference, Up: Optional Arguments
Just like define
has a shorthand notation for defining procedures
(see Lambda Alternatives), define*
is provided as an
abbreviation of the combination of define
and lambda*
.
define*-public
is the lambda*
version of
define-public
; defmacro*
and defmacro*-public
exist
for defining macros with the improved argument list handling
possibilities. The -public
versions not only define the
procedures/macros, but also export them from the current module.
define*
anddefine*-public
support optional arguments with a similar syntax tolambda*
. They also support arbitrary-depth currying, just like Guile's define. Some examples:(define* (x y #:optional a (z 3) #:key w . u) (display (list y z u)))defines a procedure
x
with a fixed argument y, an optional argument a, another optional argument z with default value 3, a keyword argument w, and a rest argument u.(define-public* ((foo #:optional bar) #:optional baz) '())This illustrates currying. A procedure
foo
is defined, which, when called with an optional argument bar, returns a procedure that takes an optional argument baz.Of course,
define*[-public]
also supports#:rest
and#:allow-other-keys
in the same way aslambda*
.
These are just like
defmacro
anddefmacro-public
except that they takelambda*
-style extended parameter lists, where#:optional
,#:key
,#:allow-other-keys
and#:rest
are allowed with the usual semantics. Here is an example of a macro with an optional argument:(defmacro* transmorgify (a #:optional b) (a 1))