Possible to execute a directive in pyswip?
allComputableThings opened this issue · comments
In Prolog, we can run a directive: (https://www.swi-prolog.org/pldoc/doc_for?object=include/1)
:- include(thread_rules).
Is it possible to the same in PYSWIP?
next(p.query(':- include(thread_rules)'))
gives:
Caused by: ':- include(thread_rules)'.
Returned: 'error(existence_error(procedure, /(:-, 1)), context(/(pyrun, 2), _1724))'.
and...
next(Prolog.query('assertz(:- include(thread_rules))'))
next(Prolog.query('h(X)'))
gives the following. (h is in the file thread_rules.pl)
Caused by: 'h(X)'.
Returned: 'error(existence_error(procedure, /(h, 1)), context(/(pyrun, 2), _1978))'.
Is it possible that this is failing because directives can go through the root rule that PYSWIP defines? (A different .query implementation needed?)
asserta(pyrun(GoalString,BindingList) :-
( atom_chars(A,GoalString),
atom_to_term(A,Goal,BindingList),
call(Goal)
)
).
Directives are file-level operations.