From d7b48d4250153aa21879609b5707af9aad434ad1 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 17 Dec 2014 15:13:32 +0100 Subject: Term.__iter__: create new Terms on each iteration --- prolog/engine.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'prolog/engine.py') 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) -- cgit v1.2.1