NextPrevUpTopContentsIndex

process-a-class-option

Generic Function
Summary

Describes how the value of a class option is parsed.

Package

clos

Signature

process-a-class-option metaclass option value => initargs

Arguments

metaclass

The metaclass of the class being parsed.

option

The defclass option name.

value

The tail of the defclass option form.

Values

initargs

A plist of initargs describing the option.

Description

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

initargs should be a plist of class initargs and values. These are added to any other initargs for the class.

Example
(defclass m1 (standard-class)
  ((title :initarg :title)))

For single-valued, evaluated title option, add a method like this:

(defmethod clos:process-a-class-option 
           ((class m1)
            (name (eql :title))
            value)
  (unless (and value (null (cdr value)))
    (error "m1 :title must have a single value."))
  (list name (car value)))
 
(defclass my-titled-class ()
  ()
  (:metaclass m1)
  (:title "Initial Title"))

If the value is not to be evaluated, the method would look like this:

(defmethod clos:process-a-class-option 
           ((class m1)
            (name (eql :title))
            value)
  (unless (and value (null (cdr value)))
    (error "m1 :title must have a single value."))
  `(,name ',value))

Now suppose we want an option whose value is a list of titles:

(defclass m2 (standard-class)
  ((titles-list :initarg :list-of-possible-titles)))

If the titles are to be evaluated, add a method like this:

(defmethod clos:process-a-class-option 
           ((class m2)
            (name (eql :list-of-possible-titles))
            value)
  (list name `(list ,@value)))

Or, if the titles should not be evaluated, add a method like this:

(defmethod clos:process-a-class-option 
           ((class m2)
            (name (eql :list-of-possible-titles))
            value)
  (list name `',value))
 
(defclass my-multi-titled-class ()
  ()
  (:metaclass m2)
  (:list-of-possible-titles 
   "Initial Title 1" 
   "Initial Title 2"))
See also

defclass
process-a-slot-option


LispWorks Reference Manual - 23 Jul 2004

NextPrevUpTopContentsIndex