5 Calling Prolog from Python
All Application Manual Name SummaryHelp

  • Documentation
    • Reference manual
    • Packages
      • SWI-Prolog Python interface
        • Calling Prolog from Python
          • Janus iterator query
          • Janus iterator apply
          • Janus access to Python locals and globals
          • Janus and Prolog truth
          • Janus class Term
          • Janus class PrologError

5.2 Janus iterator apply

Class janus.apply() is similar to janus.apply_once(), calling a Prolog predicate using functional notation style. It returns a Python iterator that enumerates all answers.

apply janus.apply(module, predicate, *input)
As janus.apply_once(), returning an iterator that returns individual answers. The example below uses Python list comprehension to create a list of integers from the Prolog built-in between/3.
>>> list(janus.apply("user", "between", 1, 6))
[1, 2, 3, 4, 5, 6]
Compatibility
PIP.
any|None janus.apply.next()
Explicitly ask for the next solution of the iterator. Normally, using the apply as an iterator is to be preferred. See discussion above. Note that this calling convention cannot distinguish between the Prolog predicate returning @none and reaching the end of the iteration.
None janus.apply.close()
Close the query. Closing a query is obligatory. When used as an iterator, the Python destructor (__del__()) takes care of closing the query.
Compatibility
PIP.