[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: What's so cool about Scheme?




   From: "Anton van Straaten" <anton@appsolutions.com>
   To: "Guy Steele - Sun Microsystems Labs" <Guy.Steele@sun.com>, 
<mike@newhall.net>
   Cc: <ll1-discuss@ai.mit.edu>
   Subject: RE: What's so cool about Scheme?
   Date: Wed, 4 Jun 2003 15:58:47 -0400
   Importance: Normal
   
   > But "bind-too-late" did work (mostly) in "old Lisp" because bindings
   > obeyed a dynamic, stack-based discipline.
   
   Ah, I get it.
   
   It occurs to me that if old Lisp had had quasiquote, an easy workaround
   would have been:
   
     (DEFINE ADD-TO-ALL (LAMBDA (Z LS)
       (MAPCAR (QUASIQUOTE (LAMBDA (X) (PLUS (UNQUOTE Z) X))) LS)))
   
   Voila, FUNARG problem solved, upward and downward.  ;)  Am I missing
   anything?

Well, what you say in the next paragraph ...

   This wouldn't work if the inner lambda expression tried to mutate the value
   of Z, so you'd have to also require that such expressions avoid mutating
   captured "variables" - or better yet, make the entire language purely
   functional and mutation-free.
   
plus the fact that you are off by one level of evaluation,
possibly misled by the fact that the example uses numbers,
which are self-evaluating, for values of Z.  It really needs
to be:

     (DEFINE ADD-TO-ALL (LAMBDA (Z LS)
       (MAPCAR (QUASIQUOTE (LAMBDA (X) (PLUS (QUOTE (UNQUOTE Z)) X))) LS)))

for full generality (such as replacing PLUS with CONS).
In modern syntax, this would be

   ... (mapcar `(lambda (x) (+ ',z x)) ls) ...

That little double-gritch  ',  pops up a lot in quasiquote programming.
   
   So: closures are a poor man's pure functional language with quasiquote???

Plus an operation that converts list structure into an executable function.

   Anton
   
   P.S. Man, my koan is going to need some work...

--Guy Steele