[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
setf order of evaluation
Date: Thu, 10 Sep 87 23:13 EDT
From: Kent M Pitman <KMP@STONY-BROOK.SCRC.Symbolics.COM>
[philosophy for future languages deleted]
As food for thought, consider the following examples...
;; #1: The case in question (using a variable as a place)
(PROGN (SETQ R '(A 1 B 2 C 3))
(SETQ S R)
(SETF (GETF R 'B) (PROGN (SETQ R NIL) 6))
(VALUES R S))
;; #2: The case in question (using a non-variable as a place)
(PROGN (SETQ R '(A 1 B 2 C 3))
(SETQ S R)
(SETF (GETF (NTHCDR 2 R) 'B) (PROGN (SETQ R NIL) 6))
(VALUES R S))
Definitely an illuminating case. This blows up trying to RPLACD NIL
with the get-setf-method of variables prescribed by CLtL, but does
what one would expect with the get-setf-method of variables I suggested
the other day. Also illuminating:
;; #2a: doesn't use GETF at all
(PROGN (SETQ R '(A 1 B 2 C 3))
(SETQ S R)
(SETF (NTHCDR 2 R) (PROGN (SETQ R NIL) 6))
(VALUES R S))
which again blows up with CLtL's setf-method for variables, but does
what one would expect with the one I suggested. These two examples
changed my mind; now I think the one I suggested is obviously right,
and the one in CLtL, evidently used by Symbolics and Lucid (and no
doubt other implementations) is obviously wrong.
;; #3: This can't work, but think hard about why not.
Works fine for me, and returns the same values as #1.
;; There's a sense in which it feels like it ought to be identical
;; to #1 above.
(PROGN (SETQ R '(A 1 B 2 C 3))
(SETQ S R)
(SETF (GETF (NTHCDR 0 R) 'B) (PROGN (SETQ R NIL) 6))
(VALUES R S))
;; #4: This is not as much like the others, but I found its return
;; value to be instructive anyway.
(PROGN (SETQ R '(A 1 B 2 C 3))
(SETQ S R)
(SETF (CAR R) (PROGN (SETQ R NIL) 6))
(VALUES R S))
Nothing surprising here.