Table of Contents

Module: dispatch ./src/peak/util/dispatch.py

Closest-match rule-based dispatching, generic functions, and multimethods

Imported modules   
from __future__ import generators
from peak.util.EigenData import EigenDict
from protocols import Interface, advise
from types import ClassType
Functions   
compareMatches
iterMatches
  compareMatches 
compareMatches ( (  ( )

Compare a pair of (rule,result) tuples in "most-specific first" order

Designed primarily for use as a list.sort() "compare function", this function returns 1, 0, or -1, according to the order that the (rule,result) pairs should be ordered in. Zero indicates that the rules are overlapping or equivalent, and therefore have no discernible ordering. Note that this may cause problems when sorting rules which are disjoint (non-overlapping), if the sorting algorithm assumes equality is transitive! For its use in this module, however, it is always sorting a list of rules that have all matched the same value, which means that none of the rules are disjoint (since they must at least overlap in the area of the matched value). Therefore, either all rules are overlapping (and thus equal) or one or more rules are "more specific" than any of the overlapping rules. This suffices for sorting matches, since we want all the unambiguous matches first, followed by the ambiguous ones. (There may also be some "less specific" rules that encompass the ambiguous ones, but since we fail at the first ambiguity, this is unimportant.

  iterMatches 
iterMatches ( matches )

Iterate over sorted list of matches; fail at first ambiguity

Exceptions   
AmbiguousRulesError( "Overlapping rules", m [ 0 ], matches [ p + 1 ] [ 0 ], )
Classes   

AmbiguousRulesError

Ambiguous rules found

Dispatch

Mapping from rules to objects (slow, but simple)

DispatchError

Any method resolution error

GenericFunction

Callable dispatcher that dispatches based on argument types

IRule

Stylesheet-like matching rule

MultiMethod

Callable dispatcher with support for chaining to "next closest" matches

NoMatchError

No match found

Signature

A rule that matches positional type signatures based on issubclass


Table of Contents

This document was automatically generated on Tue Feb 17 19:55:52 2004 by HappyDoc version 2.1