Search code examples
racketeval

in racket, eval works in the repl but not in a program


This does what I hoped:

$ racket
Welcome to Racket v8.3 [cs].
> (eval (list + 1 (list + 5 5)))
11

but this doesn't:

$ cat demo.rkt
#lang racket

(display (eval (list + 1 (list + 5 5))))
$ racket demo.rkt
?: function application is not allowed;
 no #%app syntax transformer is bound
  at: (#<procedure:+> 1 (#<procedure:+> 5 5))
  context...:

What am I doing wrong?

I searched for the error, and it seems like this has never happened to anybody before


Solution

  • Well, I'll leave the question here with the answer in case anybody else searches for that error:

    https://docs.racket-lang.org/guide/eval.html#%28part._namespaces%29

    $ cat > demo.rkt
    #lang racket
    
    (define ns (make-base-namespace))
    (display (eval (list + 1 (list + 5 5)) ns))
    $ racket demo.rkt
    11
    

    It's all explained that it works in the repl but not a program.