summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2014-12-17 15:13:32 +0100
committerAleš Smodiš <aless@guru.si>2015-08-11 14:26:00 +0200
commitd7b48d4250153aa21879609b5707af9aad434ad1 (patch)
treea4f61ce40c3a70c2d4892141a665338d5a526b28
parent487b9a3cb6849a49189c56925cbd4ddd30c230bf (diff)
Term.__iter__: create new Terms on each iteration
-rw-r--r--prolog/engine.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/prolog/engine.py b/prolog/engine.py
index 088948e..53307cb 100644
--- a/prolog/engine.py
+++ b/prolog/engine.py
@@ -46,8 +46,10 @@ class Term(object):
if not PL_is_list(self.ref):
raise TypeError('term is not a list')
ref = self.ref
- head, tail = Term(), Term()
- while PL_get_list(ref, head.ref, tail.ref):
+ while True:
+ head, tail = Term(), Term()
+ if not PL_get_list(ref, head.ref, tail.ref):
+ break
yield head
ref = tail.ref
@@ -165,6 +167,7 @@ class PrologEngine(object):
result = []
if PL_next_solution(qid):
+ solutions = list(solutions)
fid_solution = PL_open_foreign_frame()
for solution in solutions:
PL_unify(goal.ref, solution.ref)