import os, cmd, readline
from utils import dynac, ip, lexer, subst, drepr, _repr, get_module
-from stdlib import topython
+from stdlib import topython, todyna
from errors import DynaCompilerError, DynaInitializerException
from config import dotdynadir
from errors import show_traceback
return
print
for term, result in sorted((subst(q, result), result) for result in results):
- print '%s = %s.' % (term, _repr(result['$val']))
+ print '%s = %s.' % (term, _repr(todyna(result['$val'])))
print
def default(self, line, show_changed=True):
x = eval(name)(*args)
return todyna(x)
+
def topython(x):
+ #if isinstance(x, AList) or x is Nil:
+ # return {topython(k): topython(v) for k,v in x.aslist}
if isinstance(x, Cons) or x is Nil:
return [topython(y) for y in x.aslist]
return x
def todynalist(x): # TODO: get rid of this.
return todyna(x)
+
+def getkey(m, k):
+ return m[k]
+
+def setkey(m, k, v):
+ m[k] = v
+ return m
+
+
def todyna(x):
if isinstance(x, (set, Counter)):
return todyna(x)
elif isinstance(x, dict):
+ #c = Nil
+ #for k,v in x.items():
+ # c = AList(todyna([k,v]), c)
+ #return c
return todyna(x.items())
elif isinstance(x, (list, tuple)):
def iter_cons(x):
if not (isinstance(x, Cons) or x is Nil):
raise TypeError("Attemping to iterate something which isn't a list.")
- return x
+ return x.like_chart()
def in_list(x, a):
if not (isinstance(a, Cons) or a is Nil):
def __contains__(self, x):
return x in self.aslist
- def __iter__(self):
+ def like_chart(self):
for a in self.aslist:
if not isinstance(a, Term):
yield a, (None,), a
else:
yield a, (None,), a
+ def __iter__(self):
+ return iter(self.aslist)
+
def __eq__(self, other):
try:
return self.aslist == other.aslist
return False
Nil = _Nil()
+
+
+#class AList(Cons):
+#
+# def __init__(self, head, tail):
+#
+# if not (isinstance(tail, AList) or tail is Nil):
+# raise TypeError('Malformed alist: tail is not an alist')
+#
+# if not (isinstance(head, Cons) and len(head.aslist) == 2):
+# raise TypeError('Malformed alist: head is not a pair.')
+#
+# Cons.__init__(self, head, tail)
+#
+# def __repr__(self):
+# return '[%s]' % (', '.join('%s -> %s' % (_repr(k), _repr(v)) for k,v in self.aslist))
> query tree(0)
-tree(0) = ['ROOT', ['S', ['NP', 'George'], ['VP', ['V', ['V', 'love'], '-s'], ['NP', 'Laura']]], '.'].
+tree(0) = ["ROOT", ["S", ["NP", "George"], ["VP", ["V", ["V", "love"], "-s"], ["NP", "Laura"]]], "."].
> query sentence_length(10)