mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-23 13:00:34 +02:00
(SRFI-31): document.
This commit is contained in:
parent
e25853106e
commit
447e692283
1 changed files with 34 additions and 0 deletions
|
@ -28,6 +28,7 @@ get the relevant SRFI documents from the SRFI home page
|
|||
* SRFI-16:: case-lambda
|
||||
* SRFI-17:: Generalized set!
|
||||
* SRFI-19:: Time/Date library.
|
||||
* SRFI-31:: A special form `rec' for recursive evaluation.
|
||||
@end menu
|
||||
|
||||
|
||||
|
@ -2397,3 +2398,36 @@ is expressed in @code{time-duration} values.
|
|||
@end example
|
||||
|
||||
@c srfi-modules.texi ends here
|
||||
|
||||
|
||||
@node SRFI-31
|
||||
@section SRFI-31 - A special form `rec' for recursive evaluation
|
||||
|
||||
SRFI-31 defines a special form that can be used to create
|
||||
self-referential expressions more conveniently. The syntax is as
|
||||
follows:
|
||||
|
||||
@example
|
||||
@group
|
||||
<rec expression> --> (rec <variable> <expression>)
|
||||
<rec expression> --> (rec (<variable>+) <body>)
|
||||
@end group
|
||||
@end example
|
||||
|
||||
The first syntax can be used to create self-referential expressions,
|
||||
for example:
|
||||
|
||||
@lisp
|
||||
guile> (define tmp (rec ones (cons 1 (delay ones))))
|
||||
@end lisp
|
||||
|
||||
The second syntax can be used to create anonymous recursive functions:
|
||||
|
||||
@lisp
|
||||
guile> (define tmp (rec (display-n item n)
|
||||
(if (positive? n)
|
||||
(begin (display n) (display-n (- n 1))))))
|
||||
guile> (tmp 42 3)
|
||||
424242
|
||||
guile>
|
||||
@end lisp
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue