Subject: Re: #' and lambda
From: rpw3@rpw3.org (Rob Warnock)
Date: Sat, 11 Feb 2006 07:13:52 -0600
Newsgroups: comp.lang.lisp
Message-ID: <CN2dna3Zs7aNfnDenZ2dnUVZ_tidnZ2d@speakeasy.net>
Duncan Harvey <usenet-2006-01@abbrvtd.org.uk> wrote:
+---------------
| Ulrich Hobelmann <u.hobelmann@web.de> wrote:
| CL-USER 7 > (defun whoosh () (print 'global) (values))
| WHOOSH
| CL-USER 8 > (whoosh)
| GLOBAL 
| CL-USER 9 > (flet ((whoosh () (print 'lexical) (values)))
|               (whoosh)
|               (funcall #'whoosh)
|               (funcall 'whoosh))
| LEXICAL 
| LEXICAL 
| GLOBAL 
| CL-USER 10 > 
+---------------

You can go one step further:

    > (flet ((whoosh () (print 'lexical) (values))
	     (whoosh2 () (print 'lexical2) (values)))
	(let ((whoosh #'whoosh2))
	  (whoosh)
	  (funcall #'whoosh)
	  (funcall 'whoosh)
	  (funcall whoosh)))

    LEXICAL 
    LEXICAL 
    GLOBAL 
    LEXICAL2 
    > 


-Rob

p.s. And if CL had non-special globals, we could add one more still:

    > (defun whoosh2 () (print 'global2) (values))
    > (deflexical whoosh #'whoosh2)
    > (flet ((whoosh () (print 'lexical) (values))
	     (whoosh2 () (print 'lexical2) (values)))
	(let ((whoosh #'whoosh2))
	  (whoosh)
	  (funcall #'whoosh)
	  (funcall 'whoosh)
	  (funcall whoosh)
	  (funcall (symbol-value 'whoosh))))

    LEXICAL 
    LEXICAL 
    GLOBAL 
    LEXICAL2 
    GLOBAL2
    > 

But that's not CL. [And the DEFINE-SYMBOL-MACRO hack for "global
lexicals" would be cheating, since it needs to point to some *other*
global variable besides WHOOSH, to avoid contaminating WHOOSH with
"specialness", otherwise the (LET ((WHOOSH #'WHOOSH2)) ...) would
rebind the global.]

-----
Rob Warnock			<rpw3@rpw3.org>
627 26th Avenue			<URL:http://rpw3.org/>
San Mateo, CA 94403		(650)572-2607