method-combination
method-combination System Class
Class Precedence List:
method-combination, t
Description:
Every method combination object is an indirect instance of the class method-combination. A method combination object represents the information about the method combination being used by a generic function. A method combination object contains information about both the type of method combination and the arguments being used with that type.
Expanded Reference: method-combination
The method-combination System Class
method-combination objects determine how the effective method is computed from the applicable methods of a generic function. The standard method combination uses primary, :before, :after, and :around methods.
(defgeneric process (obj)
(:method-combination standard))
(defmethod process :before ((obj string))
(format t "Before: ~A~%" obj))
(defmethod process ((obj string))
(format t "Primary: ~A~%" obj))
(defmethod process :after ((obj string))
(format t "After: ~A~%" obj))
(process "test")
;; prints:
;; Before: test
;; Primary: test
;; After: test
=> NIL
Built-in Method Combinations
Common Lisp provides several built-in method combinations including +, list, progn, and, or, max, min, and append.
(defgeneric total-weight (obj)
(:method-combination +))
(defclass container () ())
(defclass heavy-container (container) ())
(defmethod total-weight + ((obj container)) 10)
(defmethod total-weight + ((obj heavy-container)) 50)
(total-weight (make-instance 'heavy-container))
=> 60