| Michele Simionato 2008-01-12, 4:29 am |
| On Jan 11, 6:45 pm, Benedikt Rosenau
> You can turn it into a loop by using begin:
>
> (define-macro (store/cc! name . body)
> (let ((k (gensym)))
> `(call-with-current-continuation
> (lambda (,k) (set! ,name ,k) ,@body))))
>
> (define cont #f)
>
> (begin
> (display (+ 1 (store/cc! cont 0)))
> (cont 1))
>
> ; As opposed to not looping on:
> ; (display (+ 1 (store/cc! cont 0)))
> ; (cont 1)
>
> Is that what you mean with "typically ... forgiving"? It
> me when I tried to understand continuations.
> I wonder if this behavior is really not specified by R5RS.
> Any takers?
I am no expert. It is something I discovered when I was playing with
continuations in Scheme about 3 or 4 years ago and got me .
The same program when run as a compiled script is looping (the right
behavior) but when run from the REPL or as an interpreted script is
not looping. I did not like this behavior and I hoped that R6RS would
have fixed that but I see now that it is not the case (Ikarus Scheme
REPL diplays exactly the same behavior). Thinking a bit more I think
the problem is endemic: in a compiled script the concept of "rest of
computation" is clear, the entire program is known to the compiler; in
the REPL the compiler cannot know what the user will type next. So
there are basically two choices: the rest of the computation is
silently ignored or you raise an error. SML/NJ choose to raise an
error and I like that choice
better.
These matters are tricky and if I got them wrong (as it already
happened to me) feel free to correct
me.
Michele Simionato
|