]> hydra-www.ietfng.org Git - dyna2/commitdiff
nonfunctional tweaks to handling of '->'.
authorTim Vieira <tim.f.vieira@gmail.com>
Wed, 10 Jul 2013 23:36:58 +0000 (19:36 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Wed, 10 Jul 2013 23:36:58 +0000 (19:36 -0400)
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/stdlib.py
src/Dyna/Backend/Python/term.py

index 83a24999774cbc2836935656526b1daa174eaba6..ea2b06ee69c006844b2387a9fff1c890c47344ca 100644 (file)
@@ -78,7 +78,7 @@ from path import path
 
 import load, post
 
-from term import Term, Cons, Nil
+from term import Term, Cons, Nil, MapsTo
 from chart import Chart
 from utils import ip, red, green, blue, magenta, yellow, parse_attrs, \
     ddict, dynac, read_anf, strip_comments, _repr, hide_ugly_filename
@@ -272,6 +272,8 @@ class Interpreter(object):
             return Cons(*args)
         if fn == 'nil/0':
             return Nil
+        if fn == '->/2':
+            return MapsTo(*args)
 
         if fn == '$key/1':
             self.new_fn(fn, '=')
index 81c62c9a0fba61b0554284c49b376a745f225106..832765228dba7afae6a19e09dad7f08e591d5f93 100644 (file)
@@ -1,5 +1,5 @@
 import re
-from term import Term, Cons, Nil
+from term import Term, Cons, Nil, MapsTo
 from collections import Counter
 from utils import pretty, pretty_print
 
@@ -77,7 +77,7 @@ def todyna(x):
         #for k,v in x.items():
         #    c = AList(todyna([k,v]), c)
         #return c
-        return todyna(x.items())
+        return todyna([MapsTo(k,v) for k,v in x.items()])
 
     elif isinstance(x, (list, tuple)):
         c = Nil
index a9f032b3c8fee67b7deaab9253939667d57d001f..f8b1e39fb23a74d7d376628b5524c1924c9d59fe 100644 (file)
@@ -31,9 +31,6 @@ class Term(object):
     def __repr__(self):
         "Pretty print a term. Will retrieve the complete (ground) term."
 
-        if self.fn == '->/2':
-            return '%s -> %s' % self.args
-
         fn = '/'.join(self.fn.split('/')[:-1])  # drop arity from name.
         if not self.args:
             return fn
@@ -134,3 +131,10 @@ class _Nil(Term):
 
 
 Nil = _Nil()
+
+
+class MapsTo(Term):
+    def __init__(self, k, v):
+        super(MapsTo, self).__init__('->/2', (k, v))
+    def __repr__(self):
+        return '%s -> %s' % self.args