[plt-scheme] Continuations and expression evaluation

From: James Coglan (jcoglan at googlemail.com)
Date: Tue Feb 17 06:20:05 EST 2009

Hi list,

Got a quick question about continuations. Take the following program:

(define r #f)
(define value #f)
(define y 2)

(set! value (+ 1
               y
               (call/cc (lambda (k)
                          (set! r k)
                          1))))

(display value)
(set! y 7)
(r 1)
(display value)

(set! y 2)
(set! value (+ 1
               (call/cc (lambda (k)
                          (set! r k)
                          1))
               y))

(display value)
(set! y 7)
(r 1)
(display value)

This prints "4449" -- in the first expression, y has already been evaluated
when we create the continuation, but in the second it has not so it is
re-evaluated each time we call the continuation. However, in the Scheme spec
it says that operands are to be evaluated in an unspecified order. Is this
at odds with the above continuation behaviour? Is this an accident or does
PLT guarantee evaluation order of operands? I couldn't tell from the spec
whether any concrete behaviour is mandated for (call/cc) embedded in a
larger expression.

-- 
James Coglan
http://github.com/jcoglan/heist
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20090217/7c0cee24/attachment.html>

Posted on the users mailing list.