[gambit-list] call/cc behavior in gambit-c vs. plt-scheme

Marc Feeley feeley at iro.umontreal.ca
Wed Jun 11 08:06:24 EDT 2008


How did you enter the code for evaluation?  Did you type it in to  
PLT's REPL and loaded it from a file in Gambit?

The behaviour of Gambit's "load" is to treat the content of the file  
as a complete sequence of commands/expressions.  It is as though the  
sequence was wrapped in a "begin" form.  Equivalently, in this case,  
it is as though the whole code was in the body of a toplevel procedure  
definition which is called once, as in:

-----------------------------------------------------------------
(define (the-whole-file)

   (define (call/ccc x) (call-with-current-continuation x))

   (define coco 1)

   (begin
    (display "begin") (newline)
    (call/ccc (lambda (c) (set! coco c)))
    (display "again") (newline)
    (display "end") (newline)
   )

   (coco 13))

(the-whole-file)
-----------------------------------------------------------------

It should be clear now why you have an endless loop.  The continuation  
stored in coco is in essence:

(lambda (result)
   (display "again")
   (newline)
   (display "end")
   (newline)
   (coco 13))

So the call (coco 13) will loop forever.

I'm actually surprised that PLT does not do the same.  Most probably  
PLT's "load" is modeled on the REPL (i.e. it is a read-eval-print loop  
which simply takes its input from a file).  So the continuation stored  
in coco is really:

(lambda (result)
   (display "again")
   (newline)
   (display "end")
   (newline)
   (next-iteration-of-the-load-repl))

But when (next-iteration-of-the-load-repl) is called, it will read end- 
of-file and thus exit load's read-eval-print loop.

I think Gambit's model is cleaner, as it allows to have the same  
semantics for load whether the file being loaded is source code or  
compiled code.

Marc


On 11-Jun-08, at 4:53 AM, Cristian Baboi wrote:

> Hello!
>
> Trying to learn scheme, I've made this small test file and tried it in
> gambit-c and plt-scheme.
>
> (define (call/ccc x) (call-with-current-continuation x))
>
> (define coco 1)
>
> (begin
>  (display "begin") (newline)
>  (call/ccc (lambda (c) (set! coco c)))
>  (display "again") (newline)
>  (display "end") (newline)
> )
>
> (coco 13)
>
> The result was:
> - plt-scheme printed:
>   begin
>   again
>   end
>   13
>
>
> - gambit-c printed:
>   begin
>   again
>   end
>   again
>   end
>   again
>   end
>   ...
>
>
> My question: which one is the intended behavior ?
>
> Thank you!
>
>
> ________ Information from NOD32 ________
> This message was checked by NOD32 Antivirus System for Linux Mail  
> Servers.
>  part000.txt - is OK
> http://www.eset.com
> _______________________________________________
> Gambit-list mailing list
> Gambit-list at iro.umontreal.ca
> https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list




More information about the Gambit-list mailing list