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


19.6 Adding methods to a multimethod

Syntax: define-method (?generic ?arg-spec …) ?body0 ?body
Syntax: define-method ((brace ?generic ?type0 ?type …) ?arg-spec …) ?body0 ?body
Syntax: define-method ?generic (?arg-spec …) ?body0 ?body
Syntax: define-method ?qualifier ?generic (?arg-spec …) ?body0 ?body
Syntax: define-method ?generic ?qualifier (?arg-spec …) ?body0 ?body
Auxiliary Syntax: :primary
Auxiliary Syntax: :around
Auxiliary Syntax: :before
Auxiliary Syntax: :after
Auxiliary Syntax: brace

Add a new method to an already existent generic function ?generic, either ordinary or starred:

The list of ?arg-spec specifies the type of the arguments for which this method specialises the generic function; an ?arg-spec can be:

(brace ?arg ?type)

Where ?arg is the formal name of the argument, ?type the type identifier of the expected operand, brace is the identifier exported by (vicare) and reexported by (vicare language-extensions multimethods).

?arg

Where ?arg is the formal name of the argument. In this case the type defaults to <top>, which is interpreted as parent of every other type (and so it has the least specificity).

If the ?generic function name comes with ?type arguments: such arguments specify the type of the return values. The types are used to validate the return values of the method’s closure object, but they do not constitute the types of values returned by the multimethod application.

If a method is defined with the same signature of an already registered method: the old method is overwritten by the new one.

In the lexical context of the ?body forms: the fluid syntax __who__ is bound to the quoted name of the multimethod, ?generic.

Syntax: add-method ?generic ?types ?closure
Syntax: add-method ?generic ?qualifier ?types ?closure
Auxiliary Syntax: :primary
Auxiliary Syntax: :around
Auxiliary Syntax: :before
Auxiliary Syntax: :after

Add a new method to an already existent multimethod ?generic, either ordinary or starred:

?types must be a list of type identifiers for which this method specialises the generic function. ?closure must be an expression which, evaluated at run–time, returns the method’s implementation closure. It is responsibility of the programmer to make sure that ?types and ?closure are coherent.


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