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

RE: setf order of evaluation



> From: Timothy Daly <DALY@ibm.com>
> To: common-lisp@SAIL.STANFORD.EDU
> 
> Given
> 
>  (setq r '(a 1 b 2 c 3))
>  (setq s r)
>  (setf (getf r 'b) (progn (setq r nil) 6))
> 
> what is the value of R and S?
> 
> Note that P97 of CLtL states that SETF guarantees the
> left-to-right order of evaluation of its arguments.
> 
> (yes, i know it is crufty to change R).
> 
> Both Symbolics and Lucid seem to generate
>  R = (B 8) and S = (A 1 B 2 C 3)

VAXLISP Version U2.2 does the same thing:

LLVS (ll)> (setq r '(a 1 b 2 c 3)) ...

(a 1 b 2 c 3)
LLVS (ll)> (setq s r) ...

(a 1 b 2 c 3)
LLVS (ll)> (setf (getf r 'b) (progn (setq r nil) 6)) ...

6
LLVS (ll)> s ...

(a 1 b 2 c 3)
LLVS (ll)> r ...

(b 6)
LLVS (ll)> (get-setf-method '(getf r b)) ...

(#:g430)
(b)
(#:g429)
(do* ((#:g431 r) 
      (#:g432 #:g431 (cddr #:g432)))
     ((atom #:g432)
      (let ((#:g428 (list* #:g430 #:g429 #:g431))) (setq r #:g428))
      #:g429)
  (cond ((atom (cdr #:g432))
         (error "Odd length property list in SETF of GETF."))
        ((eq (car #:g432) #:g430)
         (rplaca (cdr #:g432) #:g429)
         (return #:g429))))
(getf r #:g430 nil)
LLVS (ll)> (setq r '(a 1 b 2 c 3)) ...

(a 1 b 2 c 3)
LLVS (ll)> (setq s r) ...

(a 1 b 2 c 3)
LLVS (ll)> (macroexpand '(setf (getf r 'b) (progn (setq r nil) 6))) ...

(let* ((#:g446 'b) 
       (#:g445 (progn
                 (setq r nil) 
                 6)))
  (do* ((#:g447 r) 
        (#:g448 #:g447 (cddr #:g448)))
       ((atom #:g448)
        (let ((#:g444 (list* #:g446 #:g445 #:g447))) (setq r #:g444))
        #:g445)
    (cond ((atom (cdr #:g448))
           (error "Odd length property list in SETF of GETF."))
          ((eq (car #:g448) #:g446)
           (rplaca (cdr #:g448) #:g445)
           (return #:g445)))))
t

		Robert Heller
ARPANet:	Heller@CS.UMass.EDU
BITNET:		Heller@UMass.BITNET
BIX:		Heller
GEnie:		RHeller
FidoNet:	321/148 (Locks Hill BBS, Wendell, MA)
CompuServe	71450,3432
Local PV VAXen:	COINS::HELLER
UCC Cyber/DG:	Heller@CS