Reputation: 24545
Following simple 'eval'
statement works well on command line of DrRacket (as mentioned on https://docs.racket-lang.org/guide/eval.html ):
> (eval '(+ 1 2))
3
However, if kept in the script file (main area of DrRacket) and run, it produces error:
#lang racket
(eval '(+ 1 2))
Error:
+: unbound identifier;
also, no #%app syntax transformer is bound in: +
>
Where is the problem?
Upvotes: 0
Views: 174
Reputation: 236004
In Racket, this is the correct way to run eval
inside a script:
(define-namespace-anchor a)
(define ns (namespace-anchor->namespace a))
(eval '(+ 1 2) ns)
=> 3
Please refer to the documentation.
Upvotes: 1