Next: , Previous: , Up: multimethods   [Index]


19.4 Declaring multimethod definers

The following syntaxes allow the definition and merging of generic functions; merging multimethods can be useful when two libraries export generic functions bound to identifiers having the same name.

Syntax: define-generic-definer ?definer ?clause
Auxiliary Syntax: operand-type-inspector ?func

Define a new syntax, bound to the identifier ?definer, to be used to define ordinary generic functions.

The argument of the clause operand-type-inspector must be an expression which, evaluated at run–time, returns a function; such function, applied to a multimethod operand, must return the list of type UIDs. This clause is mandatory. See below for details.

The library (vicare language-extensions multimethods) defines the macro define-generic as follows:

(define-generic-definer define-generic
  (operand-type-inspector type-unique-identifiers-of))
Syntax: define-generic*-definer ?definer ?clause
Auxiliary Syntax: operand-type-inspector ?func
Auxiliary Syntax: reverse-before-methods? ?bool

Define a new syntax, bound to the identifier ?definer, to be used to define starred generic functions.

The argument of the clause operand-type-inspector must be an expression which, evaluated at run–time, returns a function; such function, applied to a multimethod operand, must return the list of type UIDs. This clause is mandatory. See below for details.

The argument of the clause reverse-before-methods? must be a boolean datum: #t if the methods qualified as :before must be reversed and so applied from the least specific to the most specific; #f if the standard method protocol must be adopted. This clause is optional: the default is to use the standard method protocol. See below for details.

The library (vicare language-extensions multimethods) defines the macro define-generic* as follows:

(define-generic*-definer define-generic*
  (operand-type-inspector  type-unique-identifiers-of)
  (reverse-before-methods? #f))
Auxiliary Syntax: operand-type-inspector ?func

The clause operand-type-inspector allows the specification of a function to map a multimethod operand to the list of UIDs representing its type. ?func must be an expression which, evaluated at run–time, returns a function.

When merging generic functions: the type inspector function is the one of the multimethod in which the others are merged.

Usually the operand-type-inspector clause selects a wrapper for type-unique-identifiers-of.

Auxiliary Syntax: reverse-before-methods? ?bool

The default methods composition protocol states that :before and :around methods are evaluated from the most specific to the least specific, while :after methods are evaluated from the least specific to the most specific.

When the clause reverse-before-methods? is used and ?bool is #t: the order of :before methods is reversed to “from the least specific to the most specific” prior to evaluating them. multimethods methods for an example of why this customisation is useful.


Next: , Previous: , Up: multimethods   [Index]