Function: cl-generic-define-generalizer

cl-generic-define-generalizer is a macro defined in cl-generic.el.gz.

Signature

(cl-generic-define-generalizer NAME PRIORITY TAGCODE-FUNCTION SPECIALIZERS-FUNCTION)

Documentation

Define a new kind of generalizer.

NAME is the name of the variable that will hold it. PRIORITY defines which generalizer takes precedence.
  The catch-all generalizer has priority 0.
  Then eql generalizer has priority 100.
TAGCODE-FUNCTION takes as first argument VALVAR which is a symbol
  and it should return a chunk of code that computes the tag of the value
  held in VALVAR.
  Further arguments are reserved for future use.
SPECIALIZERS-FUNCTION takes as first argument a tag value TAG
  and should return a list of specializers that match TAG.
  Further arguments are reserved for future use.

When called with a single argument, TAGCODE-FUNCTION can return
:need-specializers, to means this generalizer needs to know the list of
its own specializers that are applicable to the current dispatch. In that case, TAGCODE-FUNCTION receives as second argument SPECSVAR, the name of a variable that will hold the list of those specializers and it should return a pair (BINDINGS . TAGCODE) where BINDINGS is a list of (VAR FORM) that will be placed (in reverse order) in a let* and can refer to SPECSVAR to precompute any data TAGCODE may need. TAGCODE can refer to any of those bindings in addition to VALVAR. Furthermore, the value of the first VAR (or SPECSVAR, in its absence) is also passed as second argument to SPECIALIZERS-FUNCTION.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cl-generic.el.gz
(defmacro cl-generic-define-generalizer
    (name priority tagcode-function specializers-function)
  "Define a new kind of generalizer.
NAME is the name of the variable that will hold it.
PRIORITY defines which generalizer takes precedence.
  The catch-all generalizer has priority 0.
  Then `eql' generalizer has priority 100.
TAGCODE-FUNCTION takes as first argument VALVAR which is a symbol
  and it should return a chunk of code that computes the tag of the value
  held in VALVAR.
  Further arguments are reserved for future use.
SPECIALIZERS-FUNCTION takes as first argument a tag value TAG
  and should return a list of specializers that match TAG.
  Further arguments are reserved for future use.

When called with a single argument, TAGCODE-FUNCTION can return
`:need-specializers', to means this generalizer needs to know the list of
its own specializers that are applicable to the current dispatch.
In that case, TAGCODE-FUNCTION receives as second argument SPECSVAR,
the name of a variable that will hold the list of those specializers and
it should return a pair (BINDINGS . TAGCODE) where BINDINGS is a list
of (VAR FORM) that will be placed (in reverse order) in a `let*' and can
refer to SPECSVAR to precompute any data TAGCODE may need.
TAGCODE can refer to any of those bindings in addition to VALVAR.
Furthermore, the value of the first VAR (or SPECSVAR, in its absence) is
also passed as second argument to SPECIALIZERS-FUNCTION."
  (declare (indent 1) (debug (symbolp body)))
  `(defconst ,name
     (cl-generic-make-generalizer
      ',name ,priority ,tagcode-function ,specializers-function)))