[racket] begin vs +

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Mon Aug 2 09:04:48 EDT 2010

At Mon, 02 Aug 2010 21:54:54 +0900 (JST), Keiko Nakata wrote:
> Actually, I didn't see.
> 
> Why this code 
> 
> (let ([d (box #f)] [a (box 0)])
>   (print (+ (begin (let/cc k (begin (set-box! d k) (set-box! a 2) 3))) (unbox 
> a)))
>   ((unbox d) 9))
> 
> prints 511111111, rather than 59999999?

I'm not sure I'm following. Can you say more about why you expect
infinite "9"s instead of infinite "11"s?

My reading is that a 2 gets installed into the box `a' once and for
all, and then it's repeatedly added to 9. Nothing aborts the `let/cc'
body before the `(set-box! a 2)' is evaluated. Also, the `+' is outside
the `let/cc', so it is captured in the continuation along with `print'.


In case it's a question of prompts: There is only one continuation
prompt in the example, which is around the entire expression. In
particular, the `begin' above doesn't introduce a continuation prompt.
The prompt in your earlier example wasn't from `begin', but from the
top level into which the `begin' forms were spliced.



Posted on the users mailing list.