Node:define* Reference, 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* formals body | library syntax |
| define*-public formals body | library syntax |
define* and define*-public support optional arguments with
a similar syntax to lambda*. 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 Of course, |
| defmacro* name formals body | library syntax |
| defmacro*-public name formals body | library syntax |
These are just like defmacro and defmacro-public except that they
take lambda*-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))
|