[racket] eval question

From: Éric Tanter (etanter at dcc.uchile.cl)
Date: Thu Nov 20 10:39:46 EST 2014

This is answered in the Racket Guide, see section 15.1.

The reason is that you need to provide a namespace (which in the interaction mode is already initialized).

So if you do:

#lang racket/base
(define ns (make-base-namespace)) ; create namespace
(define p1 '(a . (expt 2 3)))
(eval (cdr p1) ns) ; pass it to eval

it works.

-- Éric


> On Nov 20, 2014, at 12:26 PM, Manfred Lotz <manfred.lotz at arcor.de> wrote:
> 
> Hi there,
> If I do this in a REPL 
> 
> Welcome to Racket v6.1.1.
> -> (define p1 '(a . (expt 2 3)))
> -> (eval (cdr p1))
> 8
> 
> it works fine
> 
> If I put it in a file:
> 
> #lang racket/base
> (define p1 '(a . (expt 2 3)))
> (eval (cdr p1))
> 
> I get this:
> 
> expt: unbound identifier;
> also, no #%app syntax transformer is bound
>  at: expt
>  in: (expt 2 3)
>  context...:
>   /home/manfred/tmp/test.rkt:
> [running body]
> 
> 
> What am I doing wrong? Sorry, if this is a stupid question.
> 
> 
> 
> -- 
> Manfred
> 
> 
> ____________________
>  Racket Users list:
>  http://lists.racket-lang.org/users
> 



Posted on the users mailing list.