[plt-scheme] Scope of eval?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Sun Sep 30 20:10:33 EDT 2007

On 9/30/07, Grant Rettke <grettke at acm.org> wrote:
> On 9/30/07, Jakub Piotr Cłapa <jpc at pld-linux.org> wrote:
> > Carl Eastlund wrote:
> > > Eval only works on global variables.  In your example, x is a field
> > > bound in a specific object.
> > If you want to eval in some other context either wrap it with a lambda
> > and call the returned value or play with namespace-* functions.
> How would I use lambda to go about getting the desired effect?

In your example class, you have a generic setter "v-set", but specific
getters "get-x" and "get-y".  If you replace "v-set" with "set-x" and
"set-y", you have separate methods for x and y.  Since a method is
(behind the scenes) a function, this is essentially a lambda solution.
 (You could use lambda, but inside a class, a method is usually
preferable to a function -- they don't allocate extra space in each
object, and allow inheritance.)

Carl Eastlund

Posted on the users mailing list.