diff options
Diffstat (limited to 'prolog')
-rw-r--r-- | prolog/engine.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/prolog/engine.py b/prolog/engine.py index 8ad8bfa..c859b67 100644 --- a/prolog/engine.py +++ b/prolog/engine.py @@ -117,8 +117,7 @@ class PrologEngine(object): self.answers = {} # Loads the correct solution [code] to problem [pid]. - # TODO handle library loading. - def load_solution(self, pid, code): + def load_solution(self, pid, code, facts=None): module = 'solution{}'.format(pid) fid = PL_open_foreign_frame() @@ -126,6 +125,10 @@ class PrologEngine(object): for rule in prolog.util.split(code): self.call('assertz/1', [Term('{}:({})'.format(module, rule))]) predicates.add('{}:{}'.format(module, self.predicate_indicator(rule))) + if facts: + for rule in prolog.util.split(facts): + self.call('assertz/1', [Term(rule)]) + predicates.add(self.predicate_indicator(rule)) self.call('compile_predicates/1', [Term([Term(p) for p in predicates])]) PL_discard_foreign_frame(fid) |