Next: , Up: Generalized Variables   [Contents][Index]

4.2.1 Setf Extensions

Several standard (e.g., car) and Emacs-specific (e.g., window-point) Lisp functions are setf-able by default. This package defines setf handlers for several additional functions:

The setf macro takes care to evaluate all subforms in the proper left-to-right order; for example,

(setf (aref vec (cl-incf i)) i)

looks like it will evaluate (cl-incf i) exactly once, before the following access to i; the setf expander will insert temporary variables as necessary to ensure that it does in fact work this way no matter what setf-method is defined for aref. (In this case, aset would be used and no such steps would be necessary since aset takes its arguments in a convenient order.)

However, if the place form is a macro which explicitly evaluates its arguments in an unusual order, this unusual order will be preserved. Adapting an example from Steele, given

(defmacro wrong-order (x y) (list 'aref y x))

the form (setf (wrong-order a b) 17) will evaluate b first, then a, just as in an actual call to wrong-order.