Function: cl-generic-generalizers
cl-generic-generalizers is a byte-compiled function defined in
cl-generic.el.gz.
Signature
(cl-generic-generalizers SPECIALIZER)
Documentation
Return a list of generalizers for a given SPECIALIZER.
To each kind of specializer, corresponds a generalizer which describes
how to extract a "tag" from an object which will then let us check if this
object matches the specializer. A typical example of a "tag" would be the
type of an object. It's called a generalizer because it
takes a specific object and returns a more general approximation,
denoting a set of objects to which it belongs.
A generalizer gives us the chunk of code which the
dispatch function needs to use to extract the "tag" of an object, as well
as a function which turns this tag into an ordered list of
specializers that this object matches.
The code which extracts the tag should be as fast as possible.
The tags should be chosen according to the following rules:
- The tags should not be too specific: similar objects which match the
same list of specializers should ideally use the same (eql) tag.
This insures that the cached computation of the applicable
methods for one object can be reused for other objects.
- Corollary: objects which don't match any of the relevant specializers
should ideally all use the same tag (typically nil).
This insures that this cache does not grow unnecessarily large.
- Two different generalizers G1 and G2 should not use the same tag
unless they use it for the same set of objects. IOW, if G1.tag(X1) =
G2.tag(X2) then G1.tag(X1) = G2.tag(X1) = G1.tag(X2) = G2.tag(X2).
- If G1.priority > G2.priority and G1.tag(X1) = G1.tag(X2) and this tag is
non-nil, then you have to make sure that the G2.tag(X1) = G2.tag(X2).
This is because the method-cache is only indexed with the first non-nil
tag (by order of decreasing priority).
Implementations
(cl-generic-generalizers (SPECIALIZER (head eieio--static))) in `eieio-compat.el'.
Undocumented
(cl-generic-generalizers (SPECIALIZER (head subclass))) in `eieio-core.el'.
Support for (subclass CLASS) specializers. These match if the argument is the name of a subclass of CLASS.
:extra "class" (cl-generic-generalizers SPECIALIZER) in `eieio-core.el'.
Support for dispatch on types defined by EIEIO's `defclass'.
:extra "derived-types" (cl-generic-generalizers TYPE) in `cl-lib.el'.
Support for dispatch on derived types, i.e. defined with `cl-deftype'.
:extra "oclosure-struct" (cl-generic-generalizers TYPE) in `cl-generic.el'.
Support for dispatch on types defined by `oclosure-define'.
(cl-generic-generalizers (SPECIALIZER (head derived-mode))) in `cl-generic.el'.
Support for (derived-mode MODE) specializers. Used internally for the (major-mode MODE) context specializers.
:extra "typeof" (cl-generic-generalizers TYPE) in `cl-generic.el'.
Support for dispatch on types. This currently works for built-in types and types built on top of records.
(cl-generic-generalizers (SPECIALIZER (head eql))) in `cl-generic.el'.
Support for (eql VAL) specializers. These match if the argument is `eql' to VAL.
:extra "head" (cl-generic-generalizers SPECIALIZER) in `cl-generic.el'.
Support for (head VAL) specializers. These match if the argument is a cons cell whose car is `eql' to VAL.
(cl-generic-generalizers SPECIALIZER) in `cl-generic.el'.
Support for the catch-all t specializer which always matches.
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-generic.el.gz
(cl-defgeneric cl-generic-generalizers (specializer)
"Return a list of generalizers for a given SPECIALIZER.
To each kind of `specializer', corresponds a `generalizer' which describes
how to extract a \"tag\" from an object which will then let us check if this
object matches the specializer. A typical example of a \"tag\" would be the
type of an object. It's called a `generalizer' because it
takes a specific object and returns a more general approximation,
denoting a set of objects to which it belongs.
A generalizer gives us the chunk of code which the
dispatch function needs to use to extract the \"tag\" of an object, as well
as a function which turns this tag into an ordered list of
`specializers' that this object matches.
The code which extracts the tag should be as fast as possible.
The tags should be chosen according to the following rules:
- The tags should not be too specific: similar objects which match the
same list of specializers should ideally use the same (`eql') tag.
This insures that the cached computation of the applicable
methods for one object can be reused for other objects.
- Corollary: objects which don't match any of the relevant specializers
should ideally all use the same tag (typically nil).
This insures that this cache does not grow unnecessarily large.
- Two different generalizers G1 and G2 should not use the same tag
unless they use it for the same set of objects. IOW, if G1.tag(X1) =
G2.tag(X2) then G1.tag(X1) = G2.tag(X1) = G1.tag(X2) = G2.tag(X2).
- If G1.priority > G2.priority and G1.tag(X1) = G1.tag(X2) and this tag is
non-nil, then you have to make sure that the G2.tag(X1) = G2.tag(X2).
This is because the method-cache is only indexed with the first non-nil
tag (by order of decreasing priority).")