From 57255982c795b6264be98d4a90c5c76cffd94529 Mon Sep 17 00:00:00 2001 From: timv Date: Wed, 12 Dec 2012 04:57:16 -0500 Subject: [PATCH] FIX: run_agenda termination condition FIX: more fixes pertaining to python tuple unpacking. --- bin/stdlib.py | 24 +++++++++++++++--------- examples/fib.dyna | 6 +++--- src/Dyna/Backend/Python.hs | 4 ++-- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/bin/stdlib.py b/bin/stdlib.py index b2b311b..42afa89 100644 --- a/bin/stdlib.py +++ b/bin/stdlib.py @@ -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() diff --git a/examples/fib.dyna b/examples/fib.dyna index 4ee625e..aad92b8 100644 --- a/examples/fib.dyna +++ b/examples/fib.dyna @@ -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). diff --git a/src/Dyna/Backend/Python.hs b/src/Dyna/Backend/Python.hs index f43109a..02d3625 100644 --- a/src/Dyna/Backend/Python.hs +++ b/src/Dyna/Backend/Python.hs @@ -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) -- 2.50.1