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

Re: fixing our problems with setf



    Date: 13 Oct 87 18:18 PDT
    From: Danny Bobrow <Bobrow.pa@Xerox.COM>

	Rules for the macroexpansion of (setf (foo x) y):

	(1) If the function-name foo refers to the global function
	definition, rather than a locally defined function or macro, and if
	there is a setf macro defined for foo, use the setf macro to
	compute the expansion.

	(2) If the function-name foo is defined as a macro in the
	current scope, use macroexpand-1 to expand (foo x) and try again.

	(3) If the function-name foo is defined as a special form in
	the current scope, signal an error.

	(4) Expand into the equivalent of
	(let ((#:temp-1 x)
	      (#:temp-2 y))
	  (funcall #'(setf foo) #:temp-2 #:temp-1))

    Do (1) and (4) together imply that if there is a macro definition for
    foo, and there is an flet foo, but no (setf foo) defined, that the
    expansion of
      (setf (foo ...)...)
    uses (funcall #'(setf foo) ...) rather than the macro. This seems wrong
    (inconsistent with CLtL ???).

CLtL doesn't say anything about calling #'(setf foo).

Yes, local function definitions shadow global macros and global setf macros.
This is what the cleanup committee already decided.  See the handout from
the June X3J13 meeting, issue GET-SETF-METHOD-ENVIRONMENT.

A program that defines a local foo without defining a (setf foo) is an
example of the nonsensical programs alluded to in my message.

	Normally one does not define both a setf function and a setf
	macro for the same reading function.
    But if a (setf foo) is defined locally, it is always be used, whether or
    not foo is defined locally or globally, right???

setf is an operation on function names, not functions, so when we say
that a given form expands into (funcall #'(setf foo) ...), that is independent
of the scoping of (setf foo).  Whatever (setf foo) is in scope gets called,
even if its scope is less than the scope of foo.  Another way to write
nonsensical programs, perhaps.  Of course one doesn't need setf at all
to write nonsensical programs!

    I think the rule might be stated that if there is no (setf foo) function
    AND there is a setf macro, then the macro is used, else the (setf foo)
    function is used in the expansion.  This is a slightly extended version
    of your:
	In the absence of any setf macro definition, SETF of a function
	expands into a call to the setf function.  
    But aside from these two glitches (or my misunderstanding), I agree.

You've just restated the more complicated rule that Gregor just
convinced me to get rid of.  Maybe you should talk to him (preferably
before he metamorphoses).