Thanks Matthew, that was very enlightening!
I do get the behaviour I had expected if I type `((lambda () (stop)
(stop) 42))' instead.
The funny thing is, I thought `(begin exp ...)' was nothing more than a
syntactic abbreviation of `((lambda () exp ...))', but apparently there
is an exception for the top level. Granted, this exception is described
in R5RS, but I had failed to see the consequences of this on captured
continuations!
Regards,
Bas
On 8/19/10 20:13 PM, Matthew Flatt wrote:
At Thu, 19 Aug 2010 19:04:49 +0200, Bas Steunebrink wrote:
Hi all,
From what I understand about call/cc, when a saved continuation is
invoked, the current continuation should be discarded. So I expected the
following program to just print `stop?' once; however, it doesn't stop.
Welcome to DrScheme, version 4.2.4 [3m].
Language: Pretty Big; memory limit: 128 megabytes.
> (define stop
(let ((k (call-with-current-continuation (lambda (k) k))))
(lambda ()
(display "stop?\n")
(k k))))
> (begin (stop) (stop) 42)
stop?
stop?
42
>
So is this an error in my understanding of call/cc or in DrScheme?
You need two more pieces of information:
* When `begin' appears in a top-level position, its expressions are
spliced into the top level.
* Every top-level expression is evaluated inside a "prompt" that
delimits continuation capture and invocation.
So, each call to `stop' discards only the continuation up to the prompt
that wraps the call to `stop'.
_________________________________________________
For list-related administrative tasks:
http://lists.racket-lang.org/listinfo/users