[racket] Promises and parameters
I can see why you might want or expect '(4) below, and it turns out
that changing `delay` to `delay/thread` makes the result '(4) instead
of '(5).
We could extract that facet of `delay/thread` (without the concurrency)
as
(define-syntax-rule (delay* e)
(let ([params (current-parameterization)])
(delay (call-with-parameterization
params
(lambda () e)))))
This works only because parameters are meant to be captured by threads
of computation. That is, "except for exactly when expr gets evaluated"
works in a thread- or future-like sense, but it wouldn't work out to
capture other facets of the dynamic extent. Capturing continuation
marks, for example, would make it more a question of continuation
capture.
But while I can see it that way, I don't think that thread-like
behavior is often the intent of `delay`. I think `delay` is mostly used
to compute a value just once and remember the result. For those uses,
the relevant output port, loggers, security guards, etc., are the ones
in place for the one-time computation.
At Thu, 30 Oct 2014 17:57:31 -0400, Tony Garnock-Jones wrote:
> Hi all,
>
> Does this seem like the morally-correct thing for promises to do in the
> presence of parameters?
>
> -> (define x (make-parameter 3))
> -> (define y (parameterize ((x 4)) (delay (list (x)))))
> -> (parameterize ((x 5)) (force y))
> '(5)
>
> I was expecting '(4), because I felt that delay should be more like let
> than lambda, if you see what I mean. That is, I expected that (delay
> expr) and (let ((foo expr)) (delay foo)) should be pretty similar except
> for exactly when expr gets evaluated.
>
> Tony
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users