Commit | Line | Data |
---|---|---|
98553883 IP |
1 | @c -*-texinfo-*- |
2 | @c This is part of the GNU Guile Reference Manual. | |
3 | @c Copyright (C) 2012 Free Software Foundation, Inc. | |
4 | @c See the file guile.texi for copying conditions. | |
5 | ||
6 | @node Curried Definitions | |
7 | @section Curried Definitions | |
8 | ||
9 | The macros in this section are provided by | |
10 | @lisp | |
11 | (use-modules (ice-9 curried-definitions)) | |
12 | @end lisp | |
13 | @noindent | |
14 | and replace those provided by default. | |
15 | ||
16 | Prior to Guile 2.0, Guile provided a type of definition known colloquially | |
17 | as a ``curried definition''. The idea is to extend the syntax of | |
18 | @code{define} so that you can conveniently define procedures that return | |
19 | procedures, up to any desired depth. | |
20 | ||
21 | For example, | |
22 | @example | |
23 | (define ((foo x) y) | |
24 | (list x y)) | |
25 | @end example | |
26 | is a convenience form of | |
27 | @example | |
28 | (define foo | |
29 | (lambda (x) | |
30 | (lambda (y) | |
31 | (list x y)))) | |
32 | @end example | |
33 | ||
34 | @deffn {Scheme Syntax} define (@dots{} (name args @dots{}) @dots{}) body @dots{} | |
35 | @deffnx {Scheme Syntax} define* (@dots{} (name args @dots{}) @dots{}) body @dots{} | |
36 | @deffnx {Scheme Syntax} define-public (@dots{} (name args @dots{}) @dots{}) body @dots{} | |
37 | ||
38 | Create a top level variable @var{name} bound to the procedure with | |
39 | parameter list @var{args}. If @var{name} is itself a formal parameter | |
40 | list, then a higher order procedure is created using that | |
41 | formal-parameter list, and returning a procedure that has parameter list | |
42 | @var{args}. This nesting may occur to arbitrary depth. | |
43 | ||
44 | @code{define*} is similar but the formal parameter lists take additional | |
45 | options as described in @ref{lambda* and define*}. For example, | |
46 | @example | |
47 | (define* ((foo #:keys (bar 'baz) (quux 'zot)) frotz #:rest rest) | |
48 | (list bar quux frotz rest)) | |
49 | ||
50 | ((foo #:quux 'foo) 1 2 3 4 5) | |
51 | @result{} (baz foo 1 (2 3 4 5)) | |
52 | @end example | |
53 | ||
54 | @code{define-public} is similar to @code{define} but it also adds | |
55 | @var{name} to the list of exported bindings of the current module. | |
56 | @end deffn |