]> hydra-www.ietfng.org Git - dyna2/commitdiff
Small tweaks.
authorTim Vieira <tim.f.vieira@gmail.com>
Mon, 8 Jul 2013 19:10:41 +0000 (15:10 -0400)
committerTim Vieira <tim.f.vieira@gmail.com>
Mon, 8 Jul 2013 19:10:41 +0000 (15:10 -0400)
added `range` to stdlib

tiny tweak (nonfunctional) to doctest.

small improvement to bool (runtime) type checking.

src/Dyna/Backend/Python/Backend.hs
src/Dyna/Backend/Python/dyna_doctest.py
src/Dyna/Backend/Python/interpreter.py
src/Dyna/Backend/Python/repl.py
src/Dyna/Backend/Python/stdlib.py
test/app/ptb.dynadoc
test/repl/load.dynadoc

index 79c8d79d79fbe8dc096bf1a221196d8c7a45bcdb..d6423eb446e1a7e0a7da6bcf20f6b8bcf7a3067c 100644 (file)
@@ -176,6 +176,8 @@ constants = go
   go ("int",_)     = Just $ PDBS $ call "int" []
   go ("pycall",_)  = Just $ PDBS $ call "pycall" []
 
+  go ("range",_)  = Just $ PDBS $ call "range" []
+
   go ("in",2)    = Just $ PDBS $ call "in_list" []
 
   go ("<=",2)    = Just $ PDBS $ infixOp "<="
index d3cd5ad4edbee761f4083c5abcd4dfb562197b36..244df58bcef0f539d9a679737446d2289a16d7c8 100644 (file)
@@ -18,7 +18,7 @@ def extract(code):
         for i, line in enumerate(block.split('\n')):
             if (line.startswith('|') or i == 0) and reading:
                 if line.startswith('|'):
-                    line = line[1:]
+                    line = ' ' + line[1:]
                 cmd.append(line)
             else:
                 reading = False
index b4b54d81b94fba178a3d53d949b390f7a2ad112f..a3e9bb9da3c86b86d20fbbb6c8093f1e8da78cd3 100644 (file)
@@ -628,14 +628,11 @@ def peel(fn, item):
     functor/arity, `fn`. Returns the arguments of term as a tuple of intern idxs
     and constants (possibly an empty tuple).
     """
-
-    if fn == "true/0" :
-#        assert item is True
-        assert bool(item)
+    if fn == "true/0":
+        assert item is true
         return
-    if fn == "false/0" :
-#        assert item is False
-        assert not bool(item)
+    if fn == "false/0":
+        assert item is false
         return
     assert isinstance(item, Term)
     assert item.fn == fn
index a9299ea31f4b72723e85f1831f4d3f32a01eed6f..6133c4552bfae5096e127d296ac8dc53c50fe341 100644 (file)
@@ -133,14 +133,14 @@ class REPL(cmd.Cmd, object):
 #        """
 #        ip()
 
-#    def do_debug(self, line):
-#        """
-#        Development tool. Used for view Dyna's intermediate representations.
-#        """
-#        import debug
-#        with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f:
-#            f.write(line)
-#        debug.main(f.name)
+    def do_debug(self, line):
+        """
+        Development tool. Used for view Dyna's intermediate representations.
+        """
+        import debug
+        with file(dotdynadir / 'repl-debug-line.dyna', 'wb') as f:
+            f.write(line)
+        debug.main(f.name)
 
 #    def do_run(self, filename):
 #        """
index 8e4729304f71384df5b6b9f01d3a5fe9717cb7b4..5e8e922d80f27b51954c4dc30b31aac73d46d1d9 100644 (file)
@@ -11,6 +11,11 @@ except ImportError:                       # XXX: should probably issue a warning
     def uniform(a=0, b=1):
         return _random() * (b - a) + a
 
+
+_range = range
+def range(*x):
+    return todyna(_range(*x))
+
 def split(s, delim='\s+'):
     return todynalist(re.split(delim, s))
 
index 0ee43229a4cdb61feed3ca543ae819859bc664d7..30cd48ccf8eb49a89050846a37407f5390517121 100644 (file)
 > % a strange way to get back sentences as lists
 | sentence(S, I) =
 |   T is b(tree(S)),
-|   I in pycall("range", 0, numwords(T)),
+|   I in range(0, numwords(T)),
 |   word(I, T).
 |
 | slen(S) max= _  is sentence(S, I), I.
index dce812a3ab44b47d9eeaee3749588eb4552dcc28..e25ba41a005f6ad939c5714a91d82bfc4c1e2629 100644 (file)
@@ -1,7 +1,4 @@
-> :- dispos &cons(&,&).
-| :- dispos &nil.
-|
-| % binary rules
+> % binary rules
 | rewrite(X, Y, Z) :=
 |     rules_tsv(Linenum, Cost, X, R),
 |     [Y, Z] is split(R, "\\s+"),
@@ -17,7 +14,7 @@
 | phrase(S,X,I,K) += phrase(S,Y,I,J) + phrase(S,Z,J,K) + rewrite(X,Y,Z).
 | phrase(S,W,I,I+1) += W is token(S,I), 0.
 |
-| sentence_length(S) max= token(S,I), I+1.
+| sentence_length(S) max= _ is token(S,I), I+1.
 | goal(S) += phrase(S, "ROOT", 0, sentence_length(S)).