[plt-scheme] Executing code created on the fly

From: Eli Barzilay (eli at barzilay.org)
Date: Sat Jul 26 20:57:47 EDT 2008

On Jul 26, Ihe wrote:
> I tried doing this with eval and ran into problems. I am also having
> problems using macros or syntax rules e.g
> (define-syntax make-program
>   (syntax-rules ()
>     [(make-program expr) (lambda (x y) expr)]))
> I want to be able to say
> (let ((prog-body blah))
>     (make-program prog-body))
> and have a different procedure returned depending on the value prog-
> body is set to.
> Alas this does not work.

Of course it doesn't -- `blah' in the above will be evaluated like any
other value -- the use of `make-program' makes it just as if you

  (let ((prog-body blah))
    (lambda (x y) prog-body))

> Basically I want to be able to execute these programs created on the
> fly and to be able to capture the source of each program ... I don't
> really care how it is done (except not with eval due to problems
> already experienced).

Are you sure you need `eval'?  If you do, then you'll need to set up a
proper namespace for it -- the default namespace is empty (and that's
probably causing the problems you're talking about).

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.