@@ 1,3 1,5 @@
+from operator import mul
+
def proximity(klass, mro):
return mro.index(klass)
@@ 5,7 7,7 @@ def lexicographic_mro(signature, matches
"Use dispatch ranking similar to CLOS"
# Schwartzian transform to weight match sigs, left-to-right"
mros = [klass.mro() for klass in signature]
- for (sig,func,nm),i in zip(matches,xrange(1000)):
+ for (sig,func),i in zip(matches,xrange(1000)):
matches[i] = (map(proximity, sig, mros), matches[i])
matches.sort()
return map(lambda t:t[1], matches)
@@ 26,11 28,10 @@ class GF(object):
return func(*args)
def add_rule(self, signature, func):
- self._table.append((signature, func, 0))
+ self._table.append((signature, func))
def linearize_table(self, signature):
- from operator import mul
- table = [(s,f,nm) for s,f,nm in self._table
+ table = [(s,f) for s,f in self._table
if len(s) == len(signature)
and reduce(mul, map(issubclass, signature, s))]
if not table:
@@ 38,6 39,6 @@ class GF(object):
raise TypeError("%s: no defined call signature <%s> for args (%s)" %
(self.__class__.__name__,
",".join([str(o) for o in signature]), a))
- return [(nomatch,0)]
+ return [(nomatch,)]
return map(lambda l:l[1:], lexicographic_mro(signature, table))