While playing around with Racket in DrRacket, I accidently entered in the interactions window.
(define x 7)
(define x 8)
and DrRacket allowed it, i.e. I didn't get a "duplicate definition of identifiers error message.
So to try and figure out what was going onI then entered this in the definitions window of DrRacket:
Code snippet A
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))
(eval '(begin (define x 7) (define x 8)) ns)
(eval 'x ns)
and still no "duplicate definitions error".
I then tried this also in the definitions window:
Code snippet B
(define x 9)
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))
(eval '(begin (define x 7) (define x 8)) ns)
(eval 'x ns)
and I got the error message: cannot redefine a constant x.
Can someone explain to me why in code snippet A in the definitions window
(and also simply entering (define x 7) followed by (define x 8) in the interactions window) doesn't give me a duplicate definitions error.
Historically, Scheme (not Racket) has always allowed re-definitions. A re-definition at the top level is equivalent to the mutation of an existing binding. Racket has tightened this up a bit, in that code at the top level of a module is not allowed to re-define an identifier. However, the old behavior persists in the "top level" that's used for "eval" and the interactions window.
I may be missing details here, but I believe that everything I'm telling you is true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With