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

SETF on macro-expanded forms



    Date: 19 Jun 1979 0112-PDT
    From: Guy Steele <GLS at SU-AI>
    Subject: Screw with DEFVST (which otherwise works fine)   
    To:   bug-lisp at MIT-MC

    (DEFVST GRUNT FOO BAR BAZ)
    (DEFMACRO CLOBBER (FROB) `(SETF ,FROB (CLOBBERIFIER ,FROB)) )
    (CLOBBER (GRUNT-BAR MY-FAVORITE-GRUNT))
    
    This fails to work because the two occurrences of FROB (i.e. of
    (GRUNT-BAR MY-FAVORITE-GRUNT)) in the generated SETF
    form will be EQ.  The second occurrence is evaluated first,
    and macro-expanded in the process.  As a result, the SETF
    (i.e. SETVST) sees a form as its first argument whose car
    is MACROEXPANDED rather than GRUNT-BAR, so it gets very unhappy.
    I am fixing this by writing instead
	    `(SETF ,(APPEND FROB '()) (CLOBBERIFIER ,FROB))
    but this seems to be a crock.  Is there any hope of a reasonable
    general solution to this problem?

Yes, there are several general solutions to this problem, which is
not unique to DEFVST
1) simply, during the runtime environment, set MACRO-EXPANSION-USE
   to something other than MACROEXPANDED;  like, say, (), or
   DISPLACE, or MACROMEMO.
2) during the definition of the structure, use the "temporary override"
   feature for DEFMACRO-DISPLACE-CALL;  see the latest two LISP RECENTs
   to see how (DEFMACRO (foo flag-name flag-value ...) ...)  differes
   from (DEFMACRO foo ...).  DEFVST permits the same kind of temproary
   settings for the various "flag-name"s.  WARNING!  A bug in DEFVST
   caused this to fail for DEFVST, but I just fixed that;  so try FTP'ing
   over to SAIL the latest LIBLSP;DEFVST FASL.   With the corrected
   DEFVST, I tried "(DEFVST (GRUNT DEFMACRO-DISPLACE-CALL ()) ...)
   and won properly.
3) push for a general acceptance of SETF in the maclisp community
   (which your function CLOBBER seems to be going in that direction),
   and let SETF know specifically about MACROEXPANDED.