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

An example of where setf does not do what I want.



    Date: 12 Sep 86 06:11:02 EDT (Fri)
    From: Bradley C. Kuszmaul <bradley@Think.COM>

    I want to do

      (setf (apply #'aref (cons my-array dims)) value)

    where MY-ARRAY, DIMS, and VALUE are bound to meaningful values

    Unfortunately, my reading of SETF says that the above won't work.
    If I had (ASET value array &rest dims) then I could to
      (apply #'aset (list* value my-array dims))
    to do what I want.

    How do I do what I want?

Your code should work.  First, you don't need to do that consing for
apply.  The old Zetalisp APPLY only took 2 arguments, but Common Lisp
APPLY takes 2 or more (and is like Zetalisp lexpr-funcall).

Notice (in the Symbolics [7.0] implementation)
	(setf (apply #'aref my-array dims) value)
	=> (APPLY #'ZL:ASET VALUE MY-ARRAY DIMS)
and also
	(setf (apply #'aref (cons my-array dims)) value)
	=> (APPLY #'ZL:ASET VALUE (VALUES (CONS MY-ARRAY DIMS)))

To show order of evaluation is still correct:
	(setf (apply #'aref (my-array) (dims)) (value))
	=> (LET* ((#:G8656 (MY-ARRAY))
		  (#:G8657 (DIMS)))
	     NIL
	     (APPLY #'ZL:ASET (VALUES (VALUE)) #:G8656 #:G8657))
and
	(setf (apply #'aref (cons (my-array) (dims))) (value))
	=> (LET* ((#:G8659 (CONS (MY-ARRAY) (DIMS))))
	     NIL
	     (APPLY #'ZL:ASET (VALUES (VALUE)) #:G8659)) 

What "reading of SETF" are you using?  Pages 96 and 97 explicitly
describe this situation and also use AREF as the example.  What
implementation are you using and how does it expand (or fail to expand).