Document (ice-9 curried definitions)
* doc/ref/Makefile.am (guile_TEXINFOS): Add curried.texi to list * doc/ref/curried.texi: New file. * doc/ref/guile.texi (Guile Modules): Add "Curried Definitions" to menu. * doc/ref/scheme-ideas.texi (Lambda Alternatives): Refer to "Curried Definitions" from the `define' section.
This commit is contained in:
parent
4aaceda29f
commit
9855388378
4 changed files with 64 additions and 0 deletions
|
|
@ -62,6 +62,7 @@ guile_TEXINFOS = preface.texi \
|
|||
web.texi \
|
||||
expect.texi \
|
||||
scsh.texi \
|
||||
curried.texi \
|
||||
sxml-match.texi \
|
||||
scheme-scripts.texi \
|
||||
api-overview.texi \
|
||||
|
|
|
|||
56
doc/ref/curried.texi
Normal file
56
doc/ref/curried.texi
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
@c -*-texinfo-*-
|
||||
@c This is part of the GNU Guile Reference Manual.
|
||||
@c Copyright (C) 2012 Free Software Foundation, Inc.
|
||||
@c See the file guile.texi for copying conditions.
|
||||
|
||||
@node Curried Definitions
|
||||
@section Curried Definitions
|
||||
|
||||
The macros in this section are provided by
|
||||
@lisp
|
||||
(use-modules (ice-9 curried-definitions))
|
||||
@end lisp
|
||||
@noindent
|
||||
and replace those provided by default.
|
||||
|
||||
Prior to Guile 2.0, Guile provided a type of definition known colloquially
|
||||
as a ``curried definition''. The idea is to extend the syntax of
|
||||
@code{define} so that you can conveniently define procedures that return
|
||||
procedures, up to any desired depth.
|
||||
|
||||
For example,
|
||||
@example
|
||||
(define ((foo x) y)
|
||||
(list x y))
|
||||
@end example
|
||||
is a convenience form of
|
||||
@example
|
||||
(define foo
|
||||
(lambda (x)
|
||||
(lambda (y)
|
||||
(list x y))))
|
||||
@end example
|
||||
|
||||
@deffn {Scheme Syntax} define (@dots{} (name args @dots{}) @dots{}) body @dots{}
|
||||
@deffnx {Scheme Syntax} define* (@dots{} (name args @dots{}) @dots{}) body @dots{}
|
||||
@deffnx {Scheme Syntax} define-public (@dots{} (name args @dots{}) @dots{}) body @dots{}
|
||||
|
||||
Create a top level variable @var{name} bound to the procedure with
|
||||
parameter list @var{args}. If @var{name} is itself a formal parameter
|
||||
list, then a higher order procedure is created using that
|
||||
formal-parameter list, and returning a procedure that has parameter list
|
||||
@var{args}. This nesting may occur to arbitrary depth.
|
||||
|
||||
@code{define*} is similar but the formal parameter lists take additional
|
||||
options as described in @ref{lambda* and define*}. For example,
|
||||
@example
|
||||
(define* ((foo #:keys (bar 'baz) (quux 'zot)) frotz #:rest rest)
|
||||
(list bar quux frotz rest))
|
||||
|
||||
((foo #:quux 'foo) 1 2 3 4 5)
|
||||
@result{} (baz foo 1 (2 3 4 5))
|
||||
@end example
|
||||
|
||||
@code{define-public} is similar to @code{define} but it also adds
|
||||
@var{name} to the list of exported bindings of the current module.
|
||||
@end deffn
|
||||
|
|
@ -370,6 +370,7 @@ available through both Scheme and C interfaces.
|
|||
* Expect:: Controlling interactive programs with Guile.
|
||||
* sxml-match:: Pattern matching of SXML.
|
||||
* The Scheme shell (scsh):: Using scsh interfaces in Guile.
|
||||
* Curried Definitions:: Extended @code{define} syntax.
|
||||
@end menu
|
||||
|
||||
@include slib.texi
|
||||
|
|
@ -387,6 +388,7 @@ available through both Scheme and C interfaces.
|
|||
@include sxml-match.texi
|
||||
|
||||
@include scsh.texi
|
||||
@include curried.texi
|
||||
|
||||
@node Standard Library
|
||||
@chapter Standard Library
|
||||
|
|
|
|||
|
|
@ -476,6 +476,11 @@ The corresponding forms of the alternative @code{define} syntax are:
|
|||
@noindent
|
||||
For details on how these forms work, see @xref{Lambda}.
|
||||
|
||||
Prior to Guile 2.0, Guile provided an extension to @code{define} syntax
|
||||
that allowed you to nest the previous extension up to an arbitrary
|
||||
depth. These are no longer provided by default, and instead have been
|
||||
moved to @ref{Curried Definitions}
|
||||
|
||||
(It could be argued that the alternative @code{define} forms are rather
|
||||
confusing, especially for newcomers to the Scheme language, as they hide
|
||||
both the role of @code{lambda} and the fact that procedures are values
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue