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

Re: Issue: SETF-SUB-METHODS (Version 5)

I thought about this issue for a long time this morning and found
it very confusing.  Eventualy, I decided that the proposal was
probably right, but it could have been better explained.  What
finally convinced me was the thinking below (which I do not think
is necessarily the better explanation).

(setf (getf -variable- -expr1-) -expr2-)

expands into something like:

(let* ((#:temp0 -variable-) ;let's assume we do this binding for now.
       (#:temp1 -expr1-)    ;in the example, -expr2- is just 'B.
       (#:temp2 -expr2-))   ;in the example, this does the setq.
  (setq -variable-
        (list-putprop [ ? ] #:temp1 #:temp2))

Let's assume LIST-PUTPROP returns the entire plist, which may be a new
list or a modification of the old.

Now the question is: what goes in [ ? ]?  If it's #:temp0, then in

     (setq s (setq r (list 'a 1 'b 2 'c 3)))
     (setf (getf r 'b) (progn (setq r nil) 6))

LIST-PUTPROP would get the original value or R (before it was set to
NIL), and the results would be:

     r ==> (a 1 b 6 c 3)
     s ==> (a 1 b 6 c 3) or (a 1 b 2 c 3)

The other alternative is that [ ? ] is R.  Then LIST-PUTPROP gets the
new value of R (i.e., nil), and the results are:

     r ==> (b 6)
     s ==> (a 1 b 2 c 3)

Now suppose we're doing 

   (setf (getf (car -variable-) -expr1-) -expr2-)

This expands into

   (let* ((#:temp0 -variable-)
          (#:temp1 -expr1-)
          (#:temp2 -expr2-))
     (setf (car #:temp0)
           (list-putprop (car #:temp0) #:temp1 #:temp2))

Here, (car #:temp0) acts as a sort of pointer to what we want to
change.  We can't point to a car (only to a whole cons), but we
want the car of that cons, not the cons that happens to be the
value of the variable later on.  That's what (car ...) means as
a place.  But a variable as a place wants a "pointer" to that
variable, not to it's value, because that's what a variable means
as a place.  And such a "pointer" is just the variable itself.

This suggests that [ ? ] should be R.  That is, we should dereference
the "pointer" when calling LIST-PUTPROP.

-- Jeff