[racket] begin vs +

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Mon Aug 2 09:10:54 EDT 2010

One possible source of confusion: begin that appears at the top-level
(of a module or in the REPL) or in a definition context (like the body
of a let expression or lambda expression) is treated specially from
other begins; specifically, it is treated as if the contents of the
begin were separate expressions, syntactically spliced directly into
the context (or the top-level). This is to facilitate writing macros
that expand into multiple definitions, etc.

A separate rule takes place for top-level expressions, which each get
their own prompt (as Matthew pointed out).


On Mon, Aug 2, 2010 at 8:04 AM, Matthew Flatt <mflatt at cs.utah.edu> wrote:
> 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.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.