All Manuals > CLIM 2.0 User Guide > Appendix C: The CLIM-SYS Package

C.4 Multiple-Value Setf

CLIM provides a facility, sometimes referred to as setf*, that allows setf to be used on "places" that name multiple values. For example, output-record-position returns the position of an output record as two values that correspond to the x and y coordinates. In order to change the position of an output record, the programmer would like to invoke (setf output-record-position). However, setf only takes a single value with which to modify the specified place. The setf* facility provides a "multiple-value" version of setf that allows an expression that returns multiple values to be used to update the specified place.

defgeneric* Macro

defgeneric* name lambda-list &body options

Summary: Defines a setf* generic function named name. The last argument in lambda-list is intended to be class specialized, just as normal setf generic functions are. options are as for defgeneric.

Note that defgeneric* does not define a generic function named (setf name) or (setf* name). The actual name of the generic function is implementation dependent and setf* generic functions have their own namespace.

defmethod* Macro

defmethod* name (method-qualifier* specialized-lambda-list &body body)

Summary: Defines a method for the setf* generic function named name. The last argument in specialized-lambda-list is intended to be class specialized, just as normal setf methods are. (method-qualifier)* and body are as for defgeneric. For example, output-record-position and its setf* method for a class called sample-output-record might be defined as follows:

(defgeneric output-record-position (record) 
  (declare (values x y))) 
(defgeneric* (setf output-record-position) (x y record))
(defmethod output-record-position ((record sample-output-record))
  (with-slots (x y) 
              (values x y))) 
(defmethod* (setf output-record-position) 
  (nx ny (record sample-output-record)) 
  (with-slots (x y) 
              (setf x nx 
                    y ny)))

The position of such an output record could then be changed as follows:

(setf (output-record-position record) (values nx ny)) 
(setf (output-record-position record1)  
      (output-record-position record2)) 

CLIM 2.0 User Guide - 01 Dec 2021 19:39:02