From: Tim Vieira Date: Wed, 3 Jul 2013 03:16:58 +0000 (-0400) Subject: Error when user tries to iterate over something which is not a list (e.g. using X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=18c4de7b5a62b7c056b1ae15690d1c9ec29216c8;p=dyna2 Error when user tries to iterate over something which is not a list (e.g. using 'in' operator). --- diff --git a/src/Dyna/Backend/Python/Backend.hs b/src/Dyna/Backend/Python/Backend.hs index 2de7617..e48e3d3 100644 --- a/src/Dyna/Backend/Python/Backend.hs +++ b/src/Dyna/Backend/Python/Backend.hs @@ -125,7 +125,7 @@ builtins (f,is,o) = case () of -> case is of [x,y] | isFree x && isGround y -> let - call _ vs = "iter" <> (parens $ sepBy comma $ mpv vs) <> colon -- for some reason on colon get put at the end of this line. + call _ vs = "iter_cons" <> (parens $ sepBy comma $ mpv vs) <> colon -- for some reason on colon get put at the end of this line. cdop = [OPIter x [y] "iter" DetNon (Just $ PDBS call)] cmod = [(x^.mv_var, nuniv)] in if isFree o diff --git a/src/Dyna/Backend/Python/stdlib.py b/src/Dyna/Backend/Python/stdlib.py index 9c0d2d1..f5d2965 100644 --- a/src/Dyna/Backend/Python/stdlib.py +++ b/src/Dyna/Backend/Python/stdlib.py @@ -51,3 +51,8 @@ def _todynalist(x): def get(x, i): return x[i] + +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