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

Defsetf and define-setf-method

    Date: Sun, 5 Jan 86 16:23:57 MST
    From: shebs%utah-orion@utah-cs.arpa (Stanley Shebs)

    Recently I had a bright idea concerning the complex form of defsetf and
    define-setf-method, namely that any defsetf could expand into an equivalent
    call on define-setf-method, and that this would be the right thing for
    complex defsetfs.  

That is certainly a reasonable implementation technique and in fact is what I
believe most implementations do.  Actually defsetf and define-setf-method
usually both expand into a third, internal thing.

		       Well, after a few days of screwing around with this,
    I decided that I didn't really understand how a complex defsetf was
    supposed to work, or what its full setf method should look like.  Is it
    all inherently hairy, or is there a simple relation between defsetf and
    define-setf-method that this pea-brained implementor has failed to notice?

When you use define-setf-method you write a lot of calls to gensym, but when
you use defsetf the macro-expansion of defsetf takes care of making the gensyms
itself.  See the discussion on page 103.

Here's an example (Guy, maybe this should go in the manual):

(defsetf subseq (sequence start &optional end) (new-sequence)
  `(progn (replace ,sequence ,new-sequence
		   :start1 ,start :end1 ,end)

(define-setf-method subseq (sequence start &optional end)
  (let ((seqtemp (gensym))
	(startemp (gensym))
	(endtemp (gensym))
	(stotemp (gensym)))
    (values (list seqtemp startemp endtemp)
	    (list sequence start end)
	    (list stotemp)
	    `(progn (replace ,seqtemp ,stotemp
			     :start1 ,startemp :end1 ,endtemp)
	    `(subseq ,seqtemp ,startemp ,endtemp))))