Path: utzoo!attcan!uunet!cs.utexas.edu!uwm.edu!mailrus!ncar!mephisto!pravda!buff From: buff@pravda.gatech.edu (Richard Billington) Newsgroups: comp.lang.lisp Subject: Re: FUNCALL question Message-ID: <19471@mephisto.UUCP> Date: 1 Feb 90 20:11:05 GMT References: <3277@accuvax.nwu.edu> <1990Jan28.175437.19293@hellgate.utah.edu> <1655@skye.ed.ac.uk> <386@forsight.Jpl.Nasa.Gov> Sender: news@mephisto.UUCP Reply-To: buff@pravda.UUCP (Richard Billington) Organization: Georgia Institute of Technology Lines: 73 In article <386@forsight.Jpl.Nasa.Gov> gat@robotics.Jpl.Nasa.Gov (Erann Gat) writes: >In article <1655@skye.ed.ac.uk>, jeff@aiai.ed.ac.uk (Jeff Dalton) writes: >> Indeed, an identifier can be associated with two values at once, >> one when it's interpreted as a function name, the other when it's >> interpreted as a variable. Erann Gat made the mistake of calling >> these two interpretations the symbol-function and symbol-value >> when those terms are properly applied only to symbols (acting >> as global variables and function names). Local variables and >> function names don't have symbol-values or symbol-functions in >> that sense. > >I want to thank Jeff Dalton for coming to my defense. However, the >above is totally incorrect (said with a smile). Temporary variables >do have value and function bindings. That is why there are LET and >FLET forms in CL. For example: > >(flet ((x (x) (+ x x))) > (let ((x 1)) > (x x))) > ... Hmmm, well there is certainly something more to what Jeff says than your example allows. The point he makes is that temporary variables are not equivalent to symbols, so his summary sentence is correct. What he said does not preclude your example. It is an important distinction to keep in mind. Forgetting that local variables are not symbols, I wrote a stupid piece of cute code which looked like the following: (defun foo (x) (flet ((hi () (print "hi there")) ;same for labels (bye () (print "good-bye"))) (funcall x))) and then got an error (that the function hi is undefined) when I tried the following: (foo 'hi) Whereas the following works fine: (defun hi () (print "hi there")) (defun foo (x) (funcall x)) (foo 'hi) => "hi there" This actually led me to some confusing results that only the rule "local variables are not symbols" helped explain in anyway. Given my first definition of foo, consider (defun foo1 () (flet ((hi () (print "hi there")) ;same for labels (bye () (print "good-bye"))) (funcall 'hi))) (defun foo2 () (flet ((hi () (print "hi there")) ;same for labels (bye () (print "good-bye"))) (funcall #'hi))) foo2 works, foo1 doesn't. Now consider (defun foo3 (x) (let ((hi #'(lambda () (print "hi there"))) (bye #'(lambda () (print "hi there")))) (funcall x) This does work. Having played around with this a bit, one thing is clear to me local variables are not equivalent to symbols.