Thumbnail CLOS Summary
defclass
- :initform - Default slot value. Evaluated at make-instance time.
- :initarg - Defines a keyword to make-instance that sets slot value
- :reader - slot option to define a method to read a slot value
- :writer - makes method to set slot value
- :accessor - makes two methods, a reader and a setf writer
- :allocation - determines if slot is shared (:class) or normal (omit or :instance)
- :default-initargs - Allows default values (ala initform) of already existing initargs without having to respecify slot.
- :type - Allows (but does not require) compiler to make type assumptions
- :documentation - associates a doc string with a slot
- See "Define-Class" macro for simplified interface with automatic initform, initargs and accessor.
make-instance
- No default keywords. Only if specified via :initarg.
- slot-value - Atomic function to read the value of a slot. You almost always want to use accessors instead.
- (setf slot-value) - Atomic function to write the value of a slot. Normally use a writer or (setf Accessor) function, but this internal version would be called when writing your own custom writer.
- initialize-instance - called by make-
instance, and the best place to put after methods to do bookkeeping on instance.
defmethod
- Similar to defun but can replace a var in the arglist with a (Var Type) pair
- If no generic function exists when method defined, one is created
- Most built-in data types and all classes can be specialized upon
- Cannot specialize on &optional or &key args
- For primary methods, only the single most specific method is called
- :before methods, all are executed in least-specific to most-specific order
- :after methods, all are executed in most-specific to least-specific order
- :around methods are the only type that can prevent primary methods from firing
- setf forms are considered primary methods, and thus can have before, after, and around methods associated with them
- Cannot add a method to a built-in standard (i.e. non-generic) function
defgeneric
- Defines generic function template
- Can define multiple methods in one form
- :method-combination - Can specify nonstandard method combination types
- :documentation - ala doc strings in
defun
- Cannot change a standard function into a generic one.
Table of contents
- defclass
-
- make-instance
-
- defmethod
-
- defgeneric
-