5.2.1 Janus classed Undefined and TruthVal
The class janus.Undefined() represents an undefined result under the Well Founded Semantics.
- Undefined janus.Undefined(term=None)
- Instances are never created explicitly by the user. They are created by
the calls to Prolog initiated from janus.once()
and janus.Query().
The class has a single property class
termthat represents either the delay list or the residual program. See janus.TruthVal() for details. - Enum janus.TruthVal()
- This class is a Python enumeration. Its values are passed as
the optional truth parameter to janus.once()
and
janus.Query(). The defined
instances are
- NO_TRUTHVALS
- Undefined results are reported as
True. This is quite pointless in the current design and this may go. - PLAIN_TRUTHVALS
- Return undefined results as
janus.undefined, a unique instance of the class janus.Undefined(). - DELAY_LISTS
- Return undefined results as an instance of class janus.Undefined(). thats holds the delay list in Prolog native representation. See call_delays/2.
- RESIDUAL_PROGRAM
- Return undefined results as an instance of class janus.Undefined(). thats holds the residual program in Prolog native representation. See call_residual_program/2.
The instances of this enumeration are available as attributed of the
janusmodule.
For example, given Russel's paradox defined in Prolog as below.
:- module(russel, [shaves/2]). :- table shaves/2. shaves(barber,P) :- person(P), tnot(shaves(P,P)). person(barber). person(mayor).
From Python, we may ask who shaves the barber in four ways as
illustrated below. Note that the Prolog representations for
janus.DELAY_LISTS and janus.RESIDUAL_PROGRAM
use the write_canonical/1
notation. They may later be changed to use a more human friendly
notation.
# Using NO_TRUTHVALS
>>> janus.once("russel:shaves(barber, X)", truth=janus.NO_TRUTHVALS)
{'truth': True, 'X': 'barber'}
# Using default PLAIN_TRUTHVALS (default)
>>> janus.once("russel:shaves(barber, X)")
{'truth': Undefined, 'X': 'barber'}
# Using default DELAY_LISTS
>>> janus.once("russel:shaves(barber, X)", truth=janus.DELAY_LISTS)
{'truth': :(russel,shaves(barber,barber)), 'X': 'barber'}
# Using default RESIDUAL_PROGRAM
>>> janus.once("russel:shaves(barber, X)", truth=janus.RESIDUAL_PROGRAM)
{'truth': [:-(:(russel,shaves(barber,barber)),tnot(:(russel,shaves(barber,barber))))], 'X': 'barber'}