[racket] eval question

From: Jens Axel Søgaard (jensaxel at soegaard.net)
Date: Thu Nov 20 10:42:45 EST 2014

2014-11-20 16:26 GMT+01:00 Manfred Lotz <manfred.lotz at arcor.de>:
> 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

Since the value of p1 is '(expt 2 3) eval will evaluate '(expt 2 3) in the
current namespace. In the repl the current namespace is set to
the namespace "inside the module in the definition window"


> it works fine
>
> If I put it in a file:
>
> #lang racket/base
> (define p1 '(a . (expt 2 3)))
> (eval (cdr p1))

Here the current namespace haven't been set to the "inside" yet.
Therefore the current namespace is empty, it doesn't even have
a binding for #%app which stands for standard application.

Here is one way to change the current namespace:

#lang racket/base
(define-namespace-anchor inside)
(current-namespace (namespace-anchor->namespace inside))

(define p1 '(a . (expt 2 3)))
(eval (cdr p1))



--
Jens Axel Søgaard


Posted on the users mailing list.