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

Re: DEFUN inside LET



	
    Date: Wed, 29 Jan 86 14:45:27 EST
    From: Jonathan A Rees <JAR@MC.LCS.MIT.EDU>
    Subject:  DEFUN inside LET
    
	Date: Tue, 28 Jan 1986  23:12 EST
	From: Scott E. Fahlman <Fahlman at C.CS.CMU.EDU>
    
	I'm not sure if there's actually a firm consensus on this...

    I don't understand how one can argue with p. 67 of CLtL which (to me)
    unequivocally says that DEFUN inside LET should "work":
    
    "Evaluating a DEFUN form causes the symbol ... to be a global name for
    the function specified by the LAMBDA-expression ... in the lexical
    environment in which the DEFUN form was executed."

That passage sounds unequivocal (by itself) to me too (and I am VERY
much in favor of DEFUNs in LETs).  Unfortunately, on pg.  66, is this
very equivocal passage that may imply that a DEFUN inside a LET is not
guaranteed to work in CL:

"It is not illegal to use these forms at other than top level, but whether it
is meaningful to do so depends on context [talk about waffling!]. Compilers,
for example, may not recognize these forms properly in other than top-level
contexts."

As I recall, this is the passage that has prevented a "firm consensus" and
I think there was some sort of consensus that the passage should be clarified
to unequivocally allow DEFUNs in LETs (and to state more explicitly what
forms are not meaningful in which contexts).  

    Also, since DEFUN is a macro, it's hard to imagine what it could expand
    into in order to behave much differently from this.
    
Imagine this:

(defmacro simple-defun (name lambda-list &body body)
  `(setf (symbol-function ',name)
         '(lambda ,lambda-list ,@body)))

The quote in front of the lambda ensures that the lambda expression is
defined in the null lexical environment.

	-- Nick