[racket] Definitions in cond-bodies

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Fri Jun 8 11:42:23 EDT 2012

I have found an interesting program:

#lang racket
(let ([x 1])
 (cond
   [(= x 1)
    (define u 2)
    (+ u 1)]
   [else u]))

When run gives a very reasonable error message:
    expand: unbound identifier in module in: u

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.


Welcome to DrRacket, version 5.3.0.6--2012-05-11(9401a53/a) [3m].
Language: racket; memory limit: 128 MB.
. expand: unbound identifier in module in: u
> (let ([x 1])
 (cond
   [(= x 1)
    (define u 2)
    (+ u 1)]
   [else u]))
3


Posted on the users mailing list.