All Manuals > LispWorks® User Guide and Reference Manual > 31 The CLOS Package

process-a-slot-option Generic Function

Summary

Describes how a defclass slot option is parsed.

Package

clos

Signature

process-a-slot-option metaclass option value already-processed-other-options slot => processed-options

Arguments
metaclass
The metaclass of the class being parsed.
option
The slot option name.
value
The value of the slot option.
already-processed-other-options
A plist of initargs for non-standard options that have been processed already.
slot
The whole slot description.
Values
processed-options
A plist of initargs.
Description

The generic function process-a-slot-option describes how the value of a slot option is parsed. It is called at defclass macroexpansion time. By default LispWorks parses slot options as defined in AMOP, but you need to supply a method if you need slot options with different behavior.

metaclass is the metaclass of the class being parsed.

option is the slot option name being parsed.

value is the value associated with option.

slot is the whole defclass slot description being parsed.

processed-options should be a plist of slot initargs and values containing those from already-processed-other-options together with initargs for option as required. These are added to any other initargs for the slot.

Examples
(defclass extended-class (standard-class)())
 
(defmethod clos:process-a-slot-option 
           ((class extended-class) option value 
            already-processed-options slot)
  (if (eq option :extended-slot)
      (list* :extended-slot 
             value 
             already-processed-options)
    (call-next-method)))
 
(defclass extended-direct-slot-definition 
          (clos:standard-direct-slot-definition)
  ((extended-slot :initarg :extended-slot :initform nil)))
 
(defmethod clos:direct-slot-definition-class 
           ((x extended-class) &rest initargs)
  'extended-direct-slot-definition)
 
(defclass test ()
  ((regular :initform 3)
   (extended :extended-slot t :initform 4))
  (:metaclass extended-class))

To add a slot option :special-reader whose value is a non-evaluated symbol naming a reader:

(defmethod clos:process-a-slot-option 
           ((class my-metaclass) option value
            already-processed-options slot)
  (if (and (eq option :special-reader) 
           (symbolp value))
      (list* :special-reader 
             `',value already-processed-options)
    (call-next-method)))

To allow repeated :special-reader options which are combined into a list:

(defmethod clos:process-a-slot-option 
           ((class my-metaclass) option value
            already-processed-options slot)
  (if (and (eq option :special-reader) (symbolp value))
      (let ((existing (getf 
                       already-processed-options
                       :special-reader)))
        (if existing ; this is a quoted list of symbols
            (progn
              (setf (cdr (last (cadr existing))) (list value))
              already-processed-options)
          (list* :special-reader
                 `'(,value) 
                 already-processed-options)))
    (call-next-method)))
See also

defclass
process-a-class-option


LispWorks® User Guide and Reference Manual - 01 Dec 2021 19:30:25