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

defun and lexical environments

    Date:     Wed, 2 Sep 87 16:08 EST
    From:     GODDEN%gmr.com@RELAY.CS.NET

    Am I wrong or should the following be equivalent:

    (defun foo (x)
     (defun bar (y) (list x y))

    (defun foo (x)
     (setf (symbol-function 'bar) #'(lambda (y) (list x y)))

    When I do the second form followed by (foo 1) (bar 2)
    I get (1 2) returned from bar.  But doing this after the
    first defun gives an error, unbound variable x.
    Is this a bug in the Symbolics implementation?
    Or a bug in me?

The silver bible doesn't constrain DEFUN to only work at "top level"
although Symbolics does (as do most implementations).  

Also note that 
    (defun foo (x)
     (setf (symbol-function 'bar) '(lambda (y) (list x y)))

will not do what you expect.

    Incidentally, I am talking about the Common Lisp language
    and defun is explained on p.67 of Steele (not 57 as the
    index claims).  As I read it, the two forms above should
    be equivalent.

    p.s. If any of you have any influence in the matter, please
	 try to get us a decent index in the next edition of Steele.

It is first mentioned on 57, but if you want you should get "Common
Lisp, the Index" from Coral Software.