Method Combination

The CommonLispObjectSystem provides for user-definable MethodCombinations. A MethodCombination defines which applicable methods will be called and in which order they will be called when a GenericFunction is called. Different generic functions can employ different method combinations.

This is explained in Section 7.6.6 (http://www.lisp.org/HyperSpec/Body/sec_7-6-6.html) of the CommonLispHyperSpec and in the book TheArtOfTheMetaObjectProtocol.
Quoting the CommonLispHyperSpec:

When a GenericFunction is called with particular arguments, it must determine the code to execute. This code is called the effective method for those arguments. The effective method is a combination of the applicable methods in the generic function that calls some or all of the methods.

A subclass inherits methods in the sense that any method applicable to all instances of a class is also applicable to all instances of any subclass of that class.

The effective method is determined by the following three-step procedure:

  1. Select the applicable methods.

  2. Sort the applicable methods by precedence order, putting the most specific method first.

  3. Apply method combination to the sorted list of applicable methods, producing the effective method.

When the effective method has been determined, it is invoked with the same arguments as were passed to the generic function. Whatever values it returns are returned as the values of the generic function.


CategoryCommonLisp CategoryLanguageFeature

EditText of this page (last edited March 21, 2010) or FindPage with title or text search