[plt-scheme] eval and define

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Thu Dec 28 11:30:50 EST 2006

The reason is that gensym  creates uninterned symbol, , i.e., a 
symbol that is not eq?, eqv?, or equal? to any other symbol, 
although it may print the same as another symbol.

So nik, if you really want common lisp style in this example,
please use 

(define fcn (string->symbol (symbol->string (gensym "p-"))))

instead.

Chongkai

----- Original Message ----- 
From: "Danny Yoo" <dyoo at hkn.eecs.berkeley.edu>
To: "nik gaffney" <nik at fo.am>
Cc: <plt-scheme at list.cs.brown.edu>
Sent: Thursday, December 28, 2006 8:28 AM
Subject: Re: [plt-scheme] eval and define


> 
>>> (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!
> _________________________________________________
>  For list-related administrative tasks:
>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>

Posted on the users mailing list.