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


19.3 How methods are dispatched

Here we attempt the formulation of the rules of method dispatching. A method is identified by a couple of values: the signature and the closure.

Applicability

First we need to understand when a method is applicable to a tuple of operands:

  1. Methods in a multimethod have the same number of arguments, so the tuple of operands must match that number.
  2. Given a tuple of operands, position by position, the type of the method’s argument is equal to, or a parent of, the type of the given operand.

Specificity

Now we can understand how to determine which one, among two applicable methods, is more specific for a tuple of operands. Let’s call the methods A and B.

Notice that it is forbidden to two distinct methods, in the same multimethod, to have the same signature.

Vicare types support only single inheritance, so if two methods are applicable: the homologous lists of UIDs in their signatures, have at least one eq? member (different from <top>).

The lists of UIDs in the signatures are compared in couples, from the first argument/first operand to the last argument/last operand, and from list head to list tail.

  1. If the first UIDs are eq?: the next couple is inspected.
  2. If the UID from B is a member of the list from A: A is more specific than B.