[plt-scheme] eval and define

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Thu Dec 28 10:28:14 EST 2006

>> (define fcn  (gensym "p-"))
>> fcn
> p-113
>> (eval `(define ,fcn (lambda () (+ 1 1))))
>> p-113
> . reference to undefined identifier: p-113
>> (p-113)
> . reference to undefined identifier: p-113


Hi Nik,

Here's a reworked example:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (define fcn (gensym "p-"))
> (eval `(define ,fcn (lambda () (+ 1 1))))
> (eval fcn)
#<procedure:p-3>
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


That being said, what's the nature of the dynamically generated functions 
that you're building?  It might be that, if things are restricted enough, 
that you can do without eval.  Can you give us more details?


Good luck!


Posted on the users mailing list.