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

class-extra-initargs Generic Function

Summary

Extends the valid initialization arguments of a class.

Package

clos

Signature

class-extra-initargs prototype => initargs

Arguments
prototype
A prototype instance.
Values
initargs
A list of additional initialization arguments.
Description

The generic function class-extra-initargs lets you extend the set of valid initialization arguments for a class and its subclasses. You can implement methods that specialize on prototype, which is a prototype instance.

initargs should be a list of symbols. Each symbol becomes a valid initarg for the class. By default in a non-delivered LispWorks image, make-instance and other CLOS initializations (see set-clos-initarg-checking) check that initargs passed to them are valid.

The extra initargs are used for make-instance, reinitialize-instance, update-instance-for-redefined-class and update-instance-for-different-class.

Notes

class-extra-initargs is useful only in complex cases. In most cases other ways of extending the set of valid initargs are simpler and clearer, such as the :extra-initargs class option, described in defclass.

Examples

In this session an illegal initarg :my-keyword is passed, causing make-instance to signal an error.

Then :my-keyword is added as an extra initarg, after which make-instance accepts it.

CL-USER 38 > (defclass my-class () ((a :initform nil)))
#<STANDARD-CLASS MY-CLASS 113AAA2F>
 
CL-USER 39 > (make-instance 'my-class :my-keyword 8)
 
Error: MAKE-INSTANCE is called with unknown keyword :MY-KEYWORD among the  arguments (MY-CLASS :MY-KEYWORD 8) {no keywords allowed}
  1 (continue) Ignore the keyword :MY-KEYWORD
  2 (abort) Return to level 0.
  3 Return to top loop level 0.
 
Type :b for backtrace, :c <option number> to proceed,  or :? for other options
 
CL-USER 40 : 1 > :a
 
CL-USER 41 > (defmethod clos:class-extra-initargs
                        ((x my-class))
               '(:my-keyword))
#<STANDARD-METHOD CLOS:CLASS-EXTRA-INITARGS (MY-CLASS) 1137C763>
 
CL-USER 42 > (make-instance 'my-class :my-keyword 8)
#<MY-CLASS 11368963>
See also

compute-class-potential-initargs
defclass
make-instance
set-clos-initarg-checking


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