From: Len Charest
Subject: Re: Whither EVAL?
Date: 
Message-ID: <9302101809.AA04478@AIG.Jpl.Nasa.Gov>
>        Date: Wed, 10 Feb 1993 08:42 EST
>        From: david kuznick <·······@meglos.mdcorp.ksc.nasa.gov>
> 
>        I think what you really want here is a MACRO.

No, I don't. I want the argument to MAKE-SETTER to be evaluated at run time. Therefore I want a function. This information was in my original post.

>        (Ignoring the variable capture issues. We really should be GENSYMing a
>        local variable instead of using v):

What do you mean 'ignoring the variable capture issues'? That's the whole point of creating a closure. I understand the need to gensym a unique local variable to avoid stepping on variables in the given CODE, but that's a side issue. The problem I am trying to solve is how to write a function that make a closure around an unknown piece of code.

>        With the GENSYMing:
> 
>        (defmacro make-setter (code)
> 	  (let ((var (gensym))
> 	   `(let ((,var nil))
> 	      #'(lambda ()
> 		  (print ,var)
> 		  (setq ,var ,code))))))
> 
>        Now just say (setf f (make-setter (random 10)))
>        and away you go.

But (setf f (make-setter foo)) blows up like the fourth of July.

..................................................
                                  Len Charest, Jr.
                 JPL Artificial Intelligence Group
                          ·······@aig.jpl.nasa.gov

From: david kuznick
Subject: Whither EVAL?
Date: 
Message-ID: <9302101824.AA05058@meglos.mdcorp.ksc.nasa.gov>
   Date: Wed, 10 Feb 93 10:09:33 PST
   From: ·······@aig.Jpl.Nasa.Gov (Len Charest)

   >        Date: Wed, 10 Feb 1993 08:42 EST
   >        From: david kuznick <·······@meglos.mdcorp.ksc.nasa.gov>
   > 
   >        I think what you really want here is a MACRO.

   No, I don't. I want the argument to MAKE-SETTER to be evaluated at run time. Therefore I want a function. This information was in my original post.

It will get evaluated at run-time.  What you mean is at closure
invocation-time.  You did not make that clear hence my confusion.

   >        (Ignoring the variable capture issues. We really should be GENSYMing a
   >        local variable instead of using v):

   What do you mean 'ignoring the variable capture issues'? That's the
whole point of creating a closure. I understand the need to gensym a unique local variable to avoid stepping on variables in the given CODE, but that's a side issue. The problem I am trying to solve is how to write a function that make a closure around an unknown piece of code.

I meant the variable capture issues in a MACRO.  Not everyone who
reads comp.lang.lisp is as smart as you and understands the need for
GENSYM.

   >        With the GENSYMing:
   > 
   >        (defmacro make-setter (code)
   > 	  (let ((var (gensym))
   > 	   `(let ((,var nil))
   > 	      #'(lambda ()
   > 		  (print ,var)
   > 		  (setq ,var ,code))))))
   > 
   >        Now just say (setf f (make-setter (random 10)))
   >        and away you go.

   But (setf f (make-setter foo)) blows up like the fourth of July.

   ..................................................
				     Len Charest, Jr.
		    JPL Artificial Intelligence Group
			     ·······@aig.jpl.nasa.gov

So you want foo to be evaluated in the environment of the funcalling
of the closure as opposed to the creation of it?  I don't see a nice
way to do that with a function.  It will always evaluate foo at
MAKE-SETTER time.

**
David Kuznick
·······@meglos.mdcorp.ksc.nasa.gov
MUTLEY! Do something!  - D.D.
From: Erann Gat
Subject: Re: Whither EVAL?
Date: 
Message-ID: <1lbnm3INNdti@elroy.jpl.nasa.gov>
In article <··················@AIG.Jpl.Nasa.Gov> ·······@aig.jpl.nasa.gov (Len Charest) writes:
>>        Date: Wed, 10 Feb 1993 08:42 EST
>>        From: david kuznick <·······@meglos.mdcorp.ksc.nasa.gov>
>> 
>>        I think what you really want here is a MACRO.
>
>No, I don't. I want the argument to MAKE-SETTER to be evaluated at run time.
> Therefore I want a function.
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Not necesarily.  You could explicitly EVAL the argument to the macro, i.e.:

 
        (defmacro make-setter (code)
   	  (let ((var (gensym))
   	   `(let ((,var nil))
   	      #'(lambda ()
   		  (print ,var)
 		  (setq ,var ,(eval code)))))))
                              ^^^^^

This doesn't get rid of the EVAL, but it does make your intension to
evaluate the arguument explicit.  Whether this makes a better solution
depends on a broader context than you prodvide.  Do you need to mapcar
make-setter, for example?  Or pass #'make-setter as an argument to
some other funciton?  (I shudder at the possibilities ;-)

Erann Gat
···@robotics.jpl.nasa.gov