From: timv Date: Mon, 3 Jun 2013 02:23:32 +0000 (-0400) Subject: Chart does not need update method thanks to the new Term objects. X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=48d87c9d6d4ef81f67ae0a5a883c05f7fb53117c;p=dyna2 Chart does not need update method thanks to the new Term objects. --- diff --git a/src/Dyna/Backend/Python/interpreter.py b/src/Dyna/Backend/Python/interpreter.py index 50049a9..06aff79 100644 --- a/src/Dyna/Backend/Python/interpreter.py +++ b/src/Dyna/Backend/Python/interpreter.py @@ -123,13 +123,14 @@ import os, sys from collections import defaultdict, namedtuple from argparse import ArgumentParser -from utils import ip, red, green, blue, magenta, yellow, dynahome +from utils import ip, red, green, blue, magenta, yellow, dynahome, notimplemented from defn import aggregator class AggregatorConflict(Exception): pass + # TODO: as soon as we have safe names for these things we can get rid of this. class chart_indirect(dict): def __missing__(self, key): @@ -174,10 +175,6 @@ def dump_charts(out=sys.stdout): print >> out -def notimplemented(*_,**__): - raise NotImplementedError - - # TODO: codegen should output a derive Term instance for each functor class Term(namedtuple('Term', 'fn args'), object): @@ -261,32 +258,17 @@ class Chart(object): if term.value == val: yield term.args + (term.value,) - def lookup(self, args): "find index for these args" - assert len(args) == self.ncols - 1 # XXX: lookup doesn't want val? - - assert isinstance(args, tuple) and not isinstance(args, Term) + assert len(args) == self.ncols - 1 try: return self.intern[args] except KeyError: return None - def update(self, ix, args, val): - "Update chart" - - assert len(args) == self.ncols - 1 - assert isinstance(args, tuple) and not isinstance(args, Term) - - term = self.intern[args] - term.value = val - return term - def insert(self, args, val): - assert isinstance(args, tuple) and not isinstance(args, Term) - # debugging check: row is not already in chart. assert self.lookup(args) is None, '%r already in chart with value %r' % (args, val) @@ -294,13 +276,13 @@ class Chart(object): term.value = val term.aggregator = aggregator(agg_decl[self.name]) + # indexes new term for i, x in enumerate(args): self.ix[i][x].add(term) return term - def build(fn, *args): if fn == "true/0": # TODO: I'd rather have the codegen ensure true/0 is True and false/0 is False return True diff --git a/src/Dyna/Backend/Python/utils.py b/src/Dyna/Backend/Python/utils.py index 91a3f8e..c6313b5 100644 --- a/src/Dyna/Backend/Python/utils.py +++ b/src/Dyna/Backend/Python/utils.py @@ -6,8 +6,10 @@ ip = InteractiveShellEmbed(banner1 = 'Dropping into IPython\n') black, red, green, yellow, blue, magenta, cyan, white = \ map('\033[3%sm%%s\033[0m'.__mod__, range(8)) + dynahome = os.getenv('DYNAHOME', '.') + def parse_sexpr(e): """ Parse a string representing an s-expressions into lists-of-lists. @@ -58,3 +60,8 @@ def read_anf(e): g(evals[1:]), g(unifs[1:]), result) + + +def notimplemented(*_,**__): + raise NotImplementedError +