From: Tim Vieira Date: Sat, 20 Jul 2013 18:28:01 +0000 (-0400) Subject: tweaks/cleanup X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=a53ac27b2cdd07440a23c489c14efb76d30e8cce;p=dyna2 tweaks/cleanup --- diff --git a/src/Dyna/Backend/Python/post/draw_circuit.py b/src/Dyna/Backend/Python/post/draw_circuit.py index 194c507..71b8e82 100644 --- a/src/Dyna/Backend/Python/post/draw_circuit.py +++ b/src/Dyna/Backend/Python/post/draw_circuit.py @@ -7,7 +7,6 @@ import re import webbrowser from debug import Hypergraph from cStringIO import StringIO -from utils import lexer, subst HEADER = """ diff --git a/src/Dyna/Backend/Python/stdlib.py b/src/Dyna/Backend/Python/stdlib.py index b448afb..100a9f9 100644 --- a/src/Dyna/Backend/Python/stdlib.py +++ b/src/Dyna/Backend/Python/stdlib.py @@ -42,10 +42,8 @@ def lte(x, y): def eq(x,y): """ My work around for discrepency in bool equality True==1 and False==0. - >>> eq(true, 1) false - >>> eq(1, 1.0) true """ @@ -61,16 +59,13 @@ _range = range def range(*x): return todyna(_range(*x)) - def split(s, delim='\s+'): return todyna(re.split(delim, s)) - def crash(): class Crasher(Exception): pass raise Crasher('Hey, you asked for it!') - def pycall(name, *args): """ Temporary foreign function interface - call Python functions from dyna! @@ -79,73 +74,55 @@ def pycall(name, *args): x = eval(name)(*args) return todyna(x) - def topython(x): - if islist(x): return [topython(y) for y in x.aslist] - elif isinstance(x, MapsTo): return tuple(x.args) - return x - def todyna(x): - if isinstance(x, (set, Counter)): x = list(x) x.sort() return todyna(x) - elif x is True: return true - elif x is False: return false - elif isinstance(x, dict): return todyna([MapsTo(todyna(k), todyna(v)) for k,v in x.items()]) - elif isinstance(x, (list, tuple)): c = Nil for y in reversed(x): c = Cons(todyna(y), c) return c else: - return x - def get(x, i): return x[i] - def getkey(m, k): return m[k] - def setkey(m, k, v): m[k] = v return m - def islist(x): return isinstance(x, Cons) or x is Nil - def iter_cons(x): if not islist(x): raise TypeError("Attemping to iterate something which isn't a list. %r" % (x,)) return x.like_chart() - def in_list(x, a): if not islist(a): raise TypeError("Attemping to iterate something which isn't a list. %r" % (a,)) return todyna(x in a.aslist) - # should probably be done with memoized backchaining... def read_lines(filename): with file(filename) as f: diff --git a/src/Dyna/Backend/Python/utils.py b/src/Dyna/Backend/Python/utils.py index 7a666dc..87824dc 100644 --- a/src/Dyna/Backend/Python/utils.py +++ b/src/Dyna/Backend/Python/utils.py @@ -40,17 +40,9 @@ def isbool(x): return x is true or x is false - - def _repr(x): - -# TODO: this assertion should eventually hold. -# assert x is not True and x is not False, x - if x is True: - return 'true' - elif x is False: - return 'false' - elif x is None: + #assert x is not True and x is not False, x + if x is None: return 'null' elif isinstance(x, basestring): # dyna doesn't accept single-quoted strings