Custom method combination
Factor handbook » The language » Objects » Generic words and methods

Prev:Calling less-specific methods
Next:Generic word introspection


Abstractly, a generic word can be thought of as a big chain of type conditional tests applied to the top of the stack, with methods as the bodies of each test. The method combination is this control flow glue between the set of methods, and several aspects of it can be customized:
which stack item(s) the generic word dispatches upon,
which methods out of the set of applicable methods are called

A table of built-in method combination defining words, and the method combinations themselves:
GENERIC:standard-combination
GENERIC#:standard-combination
HOOK:hook-combination
MATH:math-combination

Developing a custom method combination requires that a parsing word calling define-generic be defined; additionally, it is a good idea to implement the Definition protocol on the class of words having this method combination, to properly support developer tools.

The combination quotation passed to define-generic has stack effect ( word -- quot ). It's job is to call various introspection words, including at least obtaining the set of methods defined on the generic word, then combining these methods in some way to produce a quotation.

See also
Generic word introspection