A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://docs.racket-lang.org/reference/Delayed_Evaluation.html below:

10.3 Delayed Evaluation

10.3 Delayed Evaluation🔗ℹ

A promise encapsulates an expression to be evaluated on demand via force. After a promise has been forced, every later force of the promise produces the same result.

Returns #t if v is a promise, #f otherwise.

Creates a promise that, when

force

d, evaluates the

body

s to produce its value. The result is then cached, so further uses of

force

produce the cached value immediately. This includes multiple values and exceptions.

Like

delay

, if the last

body

produces a promise when forced, then this promise is

force

d, too, to obtain a value. In other words, this form creates a composable promise, where the computation of its body is “attached” to the computation of the following promise, and a single

force

iterates through the whole chain, tail-calling each step.

Note that the last body of this form must produce a single value, but the value can itself be a delay promise that returns multiple values.

The lazy form is useful for implementing lazy libraries and languages, where tail calls can be wrapped in a promise.

If

v

is a promise, then the promise is forced to obtain a value. If the promise has not been forced before, then the result is recorded in the promise so that future

force

s on the promise produce the same value (or values). If forcing the promise raises an exception, then the exception is similarly recorded so that forcing the promise will raise the same exception every time.

If v is forced again before the original call to force returns, then the exn:fail exception is raised.

If v is not a promise, then it is returned as the result.

Returns #t if promise has been forced.

Returns #t if promise is currently being forced. (Note that a promise can be either running or forced but not both.)

10.3.1 Additional Promise Kinds🔗ℹ

Creates a “call-by-name” promise that is similar to

delay

-promises, except that the resulting value is not cached. This kind of promise is essentially a thunk that is wrapped in a way that

force

recognizes.

If a delay/name promise forces itself, no exception is raised, the promise is never considered “running” or “forced” in the sense of promise-running? and promise-forced?.

Returns

#t

if

promise

is a promise created with

delay/name

.

Added in version 6.3 of package base.

Creates a “strict” promise: it is evaluated immediately, and the result is wrapped in a promise value. Note that the body can evaluate to multiple values, and forcing the resulting promise will return these values.

Produces a promise where an attempt to

force

the promise by a thread other than one currently running the promise causes the

force

to block until a result is available. This kind of promise is also a

synchronizable event

for use with

sync

;

sync

ing on the promise does not

force

it, but merely waits until a value is forced by another thread. The

synchronization result

is

#<void>

.

If a promise created by delay/sync is forced on a thread that is already running the promise, an exception is raised in the same way as for promises created with delay.

(delay/thread body/option ...+)

  body/option   =   body     |   #:group thread-group-expr

Like

delay/sync

, but begins the computation immediately on a newly created thread. The thread is created under the

thread group

specified by

thread-group-expr

, which defaults to

(make-thread-group)

. A

#:group

specification can appear at most once.

Exceptions raised by the bodys are caught as usual and raised only when the promise is forced. Unlike delay/sync, if the thread running body terminates without producing a result or exception, force of the promise raises an exception (instead of blocking).

(delay/idle body/option ...+)

  body/option   =   body     |   #:wait-for wait-evt-expr     |   #:work-while while-evt-expr     |   #:tick tick-secs-expr     |   #:use use-ratio-expr

If the promise is forced before the computation is done, it runs the rest of the computation immediately without waiting on events or periodically restricting evaluation.

A #:wait-for, #:work-while, #:tick, or #:use specification can appear at most once.

  maybe-group   =       |   #:group thread-group-expr  

Iterates like

for/list

, but the bodies (following any

#:break

or

#:final

clauses) are wrapped in

delay/thread

. Each

promise

is forced before the result list is returned.

Threads are created under thread-group-expr, which defaults to (make-thread-group). An optional #:group clause may be provided, in which case the threads will be created under that thread group.

This form does not support returning multiple values.

Example:

thread 2 slept for 10.0 milliseconds

thread 1 slept for 10.0 milliseconds

thread 3 slept for 13.0 milliseconds

thread 0 slept for 16.0 milliseconds

thread 4 slept for 20.0 milliseconds

cpu time: 22 real time: 20 gc time: 0

'(0 1 2 3 4)

Added in version 8.6.0.4 of package base.

Added in version 8.6.0.4 of package base.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4