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

Problems with CommonLoops

As time goes on PCL is becoming CLOS. Gregor mentioned in his release
message that with-slots has changed to conform to the latest definition.
Although I cannot speak for Gregor or Xerox, there will soon be increased
pressure to conform to CLOS, and people using PCL should be aware that it
will be changing to meet that specification. Such changes cannot be viewed
as ``problems'' with PCL. Here is the latest specification of with-slots:

with-slots							Macro


The macro with-slots creates a lexical context for referring to specified
slots as though they were variables.  Within such a context the value of
the slot can be specified by using its slot name, as if it were a
lexically bound variable.  Both setf and setq can be used to set the value
of the slot.

The macro with-slots translates an appearance of the slot name as a
variable into a call to slot-value.


with-slots ({slot-entry}*) instance-form body)

slot-entry::= slot-name | (variable-name slot-name)


(with-slots (x y)
  (sqrt (+ (* x x)
           (* y y))))

(with-slots ((x1 x)
             (y1 y))
  (with-slots ((x2 x)
               (y2 y))
     (psetf x1 x2
            y1 y2))))

  (with-slots (x y)
    (setq x (1+ x)
          y (1+ y)))


A with-slots expression of the form:

(with-slots (slot-entry1...slot-entryn) instance

expands into the equivalent of

(let ((I instance))
  (symbol-macrolet (Q1...Qn)

where Qi is 

(slot-entryi (slot-value I 'slot-entryi))

if slot-entryi is a symbol, and is

(variable-namei (slot-value I 'slot-namei))

if slot-entryi is of the form 

(variable-namei slot-namei)

See Also: