yuce / pyswip

PySwip is a Python - SWI-Prolog bridge enabling to query SWI-Prolog in your Python programs. It features an (incomplete) SWI-Prolog foreign language interface, a utility class that makes it easy querying with Prolog and also a Pythonic interface.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Possible to execute a directive in pyswip?

allComputableThings opened this issue · comments

commented

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)
                    )
          ).
commented

Directives are file-level operations.