]> hydra-www.ietfng.org Git - dyna2/commitdiff
FIX: run_agenda termination condition
authortimv <tim.f.vieira@gmail.com>
Wed, 12 Dec 2012 09:57:16 +0000 (04:57 -0500)
committertimv <tim.f.vieira@gmail.com>
Wed, 12 Dec 2012 09:57:16 +0000 (04:57 -0500)
FIX: more fixes pertaining to python tuple unpacking.

bin/stdlib.py
examples/fib.dyna
src/Dyna/Backend/Python.hs

index b2b311bbc03b2a5f3cde6c80eb2f3a4872687dad..42afa89900ca8ce859cc0a980ab011ce84498ba6 100644 (file)
@@ -25,7 +25,7 @@ Call indirection
 
 """
 
-#from debug import ultraTB2; ultraTB2.enable()
+from debug import ultraTB2; ultraTB2.enable()
 #from debug import saverr; saverr.enable(editor=True)
 
 import os, sys, math, operator
@@ -222,11 +222,9 @@ def peel(fn, x):
     `functor_arity`. Returns arguments of term as a arity-tuple of intern idxs and
     constants.
     """
-    if not isinstance(x, tuple):
-        return None
+    assert isinstance(x, tuple)
     (fa, idx) = x
-    if fa != fn:
-        return None
+    assert fa == fn
     return chart[fn].data[idx][:-1]  # minus val
 
 
@@ -278,7 +276,7 @@ def run_agenda():
 
         if was == now:
             print '    unchanged'
-            return
+            continue
 
         chart[fn].data[idx][-1] = now
 
@@ -326,7 +324,9 @@ aggr = {
 
 
 def delete(item, val):
-    # XXX: very ugly handling of deletion
+    # XXX: very ugly handling of deletion by global variable; should probably
+    # target only handler at a time, because this will get called more times
+    # than it should.
     global _delete
     _delete = True
     update_dispatcher(item, val)
@@ -347,6 +347,12 @@ execfile(dyna + '.plan')
 for xxx in initializer.handlers:
     xxx()
 
-run_agenda()
+def run():
+    try:
+        run_agenda()
+    except KeyboardInterrupt:
+        pass
+    finally:
+        dump_charts()
 
-dump_charts()
+run()
index 4ee625e81e057478b53ad208560aed2e4f0fd066..aad92b8a6c14fc6187e93d91607a70e4164e0f3f 100644 (file)
@@ -1,5 +1,5 @@
 % Fibonacci numbers
-f(1) := 1+0 .
-f(2) := 1+0 .
-f(X) := f(X-1) + f(X-2).
+f(1) += 1+0 .
+f(2) += 1+0 .
+f(X) += f(X-1) + f(X-2).
 
index f43109a0f47292b3c79486b6ce08dec60cb7ee1d..02d36255a81e427ccea275a1c52a74ddacda5543 100644 (file)
@@ -85,7 +85,7 @@ pdope (OPGetArgsIf vs id f) =
                 <> "peel" <> (parens $ fa f vs <> comma <> pretty id)
      )
 
-    `above` "except TypeError: continue"   -- you'll get a "TypeError: 'NoneType' is not iterable."
+    `above` "except (TypeError, AssertionError): continue"   -- you'll get a "TypeError: 'NoneType' is not iterable."
 
 
 pdope (OPBuild v vs f) = pretty v <+> equals
@@ -103,7 +103,7 @@ pdope (OPIter o m f) =
 fa f a = dquotes $ pretty f <> "/" <> (text $ show $ length a)
 
 -- this comes up because can't assign to ()
-tupledOrUnderscore vs = if length vs > 0 then tupled (map pretty vs) else text "_"
+tupledOrUnderscore vs = if length vs > 0 then parens ((sepBy "," $ map pretty vs) <> ",") else text "_"
 
 pslice vs = brackets $
        sepBy "," (map (\x -> case x of (MF v) -> ":" ; (MB v) -> pretty v) vs)