mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-12 23:00:22 +02:00
(Delayed Evaluation): Add delay, reword
promise? and force a bit, describe recursive forcing of a promise by its own code.
This commit is contained in:
parent
9e8c5bd0be
commit
f0d1cf6f29
1 changed files with 23 additions and 7 deletions
|
@ -319,20 +319,36 @@ list @code{("" ".scm")}.
|
||||||
|
|
||||||
@node Delayed Evaluation
|
@node Delayed Evaluation
|
||||||
@section Delayed Evaluation
|
@section Delayed Evaluation
|
||||||
|
@cindex delayed evaluation
|
||||||
|
@cindex promises
|
||||||
|
|
||||||
[delay]
|
Promises are a convenient way to defer a calculation until its result
|
||||||
|
is actually needed, and to run such a calculation only once.
|
||||||
|
|
||||||
|
@deffn syntax delay expr
|
||||||
|
@rnindex delay
|
||||||
|
Return a promise object which holds the given @var{expr} expression,
|
||||||
|
ready to be evaluated by a later @code{force}.
|
||||||
|
@end deffn
|
||||||
|
|
||||||
@deffn {Scheme Procedure} promise? obj
|
@deffn {Scheme Procedure} promise? obj
|
||||||
@deffnx {C Function} scm_promise_p (obj)
|
@deffnx {C Function} scm_promise_p (obj)
|
||||||
Return true if @var{obj} is a promise, i.e. a delayed computation
|
Return true if @var{obj} is a promise.
|
||||||
(@pxref{Delayed evaluation,,,r5rs.info,The Revised^5 Report on Scheme}).
|
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
@rnindex force
|
@rnindex force
|
||||||
@deffn {Scheme Procedure} force x
|
@deffn {Scheme Procedure} force p
|
||||||
@deffnx {C Function} scm_force (x)
|
@deffnx {C Function} scm_force (p)
|
||||||
If the promise @var{x} has not been computed yet, compute and
|
Return the value obtained from evaluating the @var{expr} in the given
|
||||||
return @var{x}, otherwise just return the previously computed
|
promise @var{p}. If @var{p} has previously been forced then its
|
||||||
|
@var{expr} is not evaluated again, instead the value obtained at that
|
||||||
|
time is simply returned.
|
||||||
|
|
||||||
|
During a @code{force}, an @var{expr} can call @code{force} again on
|
||||||
|
its own promise, resulting in a recursive evaluation of that
|
||||||
|
@var{expr}. The first evaluation to return gives the value for the
|
||||||
|
promise. Higher evaluations run to completion in the normal way, but
|
||||||
|
their results are ignored, @code{force} always returns the first
|
||||||
value.
|
value.
|
||||||
@end deffn
|
@end deffn
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue