[plt-scheme] Scope of eval?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sat Sep 29 17:03:05 EDT 2007

Eval only works on global variables.  In your example, x is a field
bound in a specific object.

--Carl

On 9/29/07, Grant Rettke <grettke at acm.org> wrote:
> What is wrong with this example?
>
> Why isn't x in scope?
>
> (require (lib "class.ss"))
> (define example%
>   (class* object% ()
>     (define x 0)
>     (define y "hello")
>     (define/public (v-set name value)
>       (eval `(set! ,name ,value)))
>     (define/public (get-x) x)
>     (define/public (get-y) y)
>     (super-new)))
>
> (define foo (new example%))
> (send foo get-x)
> (send foo v-set 'x 10)
> => error set!: cannot set undefined identifier: x


Posted on the users mailing list.