[racket] Definitions in cond-bodies
Ah silly me, another senior moment :-)
On Jun 8, 2012, at 12:06 PM, Robby Findler wrote:
> Yes, of course it is and that first branch executes and thus the error
> in the second branch (now a runtime error, thanks to the repl), is not
> signaled.
>
> Robby
>
> On Fri, Jun 8, 2012 at 11:01 AM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> With all due respect, I disagree. Like Jens, I consider the (define u ..) nested and scoped inside the first cond branch.
>>
>>
>> On Jun 8, 2012, at 11:56 AM, Sam Tobin-Hochstadt wrote:
>>
>>> On Fri, Jun 8, 2012 at 11:42 AM, Jens Axel Søgaard
>>> <jensaxel at soegaard.net> wrote:
>>>>
>>>> When
>>>>
>>>> (let ([x 1])
>>>> (cond
>>>> [(= x 1)
>>>> (define u 2)
>>>> (+ u 1)]
>>>> [else u]))
>>>>
>>>> is pasted into the interaction window, I get 3 !
>>>>
>>>> I was expecting an error.
>>>
>>> This is the same behavior as:
>>>
>>> -> (if #f x 1)
>>> 1
>>>
>>> What's happening is that `#%top` behaves differently at the REPL than
>>> in a module. This enables you to write:
>>>
>>> -> (define (even? x) (or (zero? x) (odd? (sub1 x))))
>>> -> (define (odd? x) (or (= x 1) (even? (sub1 x))))
>>>
>>> without getting an error when entering the first line.
>>> --
>>> sam th
>>> samth at ccs.neu.edu
>>>
>>> ____________________
>>> Racket Users list:
>>> http://lists.racket-lang.org/users
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users