www.delorie.com/gnu/docs/guile/guile_259.html   search  
Buy GNU books!

Guile Reference Manual

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

23.2.4 define* Reference

Just like define has a shorthand notation for defining procedures (see section 14.2.4 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.

library syntax: define* formals body
library syntax: define*-public formals body
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 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 as lambda*.

library syntax: defmacro* name formals body
library syntax: defmacro*-public name formals body
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))

  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003