[plt-scheme] Re: Executing code created on the fly

From: Ihe (wookies at talk21.com)
Date: Sat Jul 26 22:20:43 EDT 2008

On Jul 26, 7:57 pm, Eli Barzilay <e... at barzilay.org> wrote:
> 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
> wrote:
>
>   (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).
>

I am posting to ask for a method that doesn't use eval.


Posted on the users mailing list.