pl_search_cpp 2.2
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
pl_search Namespace Reference

Classes

class  ChoicePred
 A base class that represents a choice predicate. More...
 
class  CList
 Represents a list of terms. More...
 
class  DisjPred
 Represents a disjunction of predicates. More...
 
class  FailPred
 Represents a failure predicate that always fails when called. More...
 
class  IfThenElse
 Represents the equivalent of Prolog if-then-else i.e. (G1 -> G2; G3) - similar to (G1, !, G2; G3) More...
 
class  Loop
 Represents a loop predicate that iterates over instances of a predicate. More...
 
class  LoopBodyFactory
 LoopBodyFactory is an abstract base class used for generating instances of a predicate class used in the body of a loop. See the Loop class for details of how this is used. More...
 
class  NotNot
 Represents an equivalent of the Prolog call \+\+Pred. The aim is to determine if Pred succeeds without binding any variables in the call. More...
 
class  Once
 Represents the equivalent of Prolog's once(Pred). The aim is to remove any choicepoints produced by Pred. More...
 
class  PAtom
 Represents a Prolog atom. More...
 
class  PFloat
 Represents a Prolog float. More...
 
class  PInt
 Represents a Prolog integer. More...
 
class  Pred
 Base class for Prolog-like predicates. More...
 
class  PVar
 Represents a Prolog variable. More...
 
class  Term
 Abstract base class for terms that approximate Prolog terms. More...
 
class  Trail
 The Trail class is used to manage variable bindings during the execution of Prolog-like predicates. More...
 
struct  trail_entry
 
class  UpdatablePVar
 UpdatableVar implements what some Prologs call updatable assignment. More...
 
class  VarChoicePred
 Represents a choice predicate that makes choices for a variable from a set of terms. More...
 

Typedefs

typedef std::shared_ptr< PredPredPtr
 Typedef for a shared pointer to a Pred object.
 
typedef std::shared_ptr< TermTermPtr
 Typedefs for shared pointers to Terms and subclasses.
 
typedef std::shared_ptr< PVarPVarPtr
 
typedef std::shared_ptr< PIntPIntPtr
 
typedef std::shared_ptr< PFloatPFloatPtr
 
typedef std::shared_ptr< PAtomPAtomPtr
 
typedef std::shared_ptr< CListCListPtr
 
typedef std::shared_ptr< UpdatablePVarUpdatablePVarPtr
 
typedef std::shared_ptr< LoopBodyFactoryLoopBodyFactoryPtr
 

Functions

PredPtr conjunction (std::vector< PredPtr > preds)
 Represents a conjunction of predicates by chaining them together via continuations. The continuations of each predicate is modified to point to the next predicate in the conjunction. The continuation of the last predicate in the conjunction is not modified.
 
std::string repr (PredPtr pred)
 
bool unify (TermPtr t1, TermPtr t2, Trail *trail)
 Unifies two terms, binding variables as necessary.
 
bool operator== (Term &t1, Term &t2)
 == test for TermPtrs
 
bool operator< (Term &t1, Term &t2)
 < operator for Terms. Approximates the < operator in Prolog. The ordering is as follows: pvar < pint, pfloat < patom < clist < user-defined classes "older" vars are less than "newer" vars patoms are ordered by name pints and pfloats are ordered by value clists are ordered by the first element, then the second, etc.
 
bool operator<= (Term &t1, Term &t2)
 <= operator for Terms
 

Variables

std::shared_ptr< FailPredfail_pred = std::make_shared<FailPred>(nullptr)
 A shared pointer to a reusable failure predicate.
 

Typedef Documentation

◆ CListPtr

typedef std::shared_ptr<CList> pl_search::CListPtr

◆ LoopBodyFactoryPtr

◆ PAtomPtr

typedef std::shared_ptr<PAtom> pl_search::PAtomPtr

◆ PFloatPtr

typedef std::shared_ptr<PFloat> pl_search::PFloatPtr

◆ PIntPtr

typedef std::shared_ptr<PInt> pl_search::PIntPtr

◆ PredPtr

typedef std::shared_ptr<Pred> pl_search::PredPtr

Typedef for a shared pointer to a Pred object.

◆ PVarPtr

typedef std::shared_ptr<PVar> pl_search::PVarPtr

◆ TermPtr

typedef std::shared_ptr<Term> pl_search::TermPtr

Typedefs for shared pointers to Terms and subclasses.

◆ UpdatablePVarPtr

typedef std::shared_ptr<UpdatablePVar> pl_search::UpdatablePVarPtr

Function Documentation

◆ conjunction()

PredPtr pl_search::conjunction ( std::vector< PredPtr preds)

Represents a conjunction of predicates by chaining them together via continuations. The continuations of each predicate is modified to point to the next predicate in the conjunction. The continuation of the last predicate in the conjunction is not modified.

Creates a conjunction of predicates.

Parameters
predsA vector of shared pointers to the predicates.
Returns
A shared pointer to the first predicate in the conjunction.

◆ operator<()

bool pl_search::operator< ( Term t1,
Term t2 
)

< operator for Terms. Approximates the < operator in Prolog. The ordering is as follows: pvar < pint, pfloat < patom < clist < user-defined classes "older" vars are less than "newer" vars patoms are ordered by name pints and pfloats are ordered by value clists are ordered by the first element, then the second, etc.

< operator for Terms.

Parameters
t1The first term.
t2The second term.
Returns
True if the first term is less than the second term, false otherwise.

◆ operator<=()

bool pl_search::operator<= ( Term t1,
Term t2 
)

<= operator for Terms

<= operator for Term

Parameters
t1The first term.
t2The second term.
Returns
True if the first term is less than or equal to the second term, false otherwise.

◆ operator==()

bool pl_search::operator== ( Term t1,
Term t2 
)

== test for TermPtrs

== operator for Terms

Parameters
t1The first term.
t2The second term.
Returns
True if the terms are equal using the isEqualTo method, false otherwise.

◆ repr()

std::string pl_search::repr ( PredPtr  pred)

◆ unify()

bool pl_search::unify ( TermPtr  t1,
TermPtr  t2,
Trail trail 
)

Unifies two terms, binding variables as necessary.

Unifies two terms.

Parameters
t1The first term.
t2The second term.
trailPointer to the Trail for managing variable bindings.
Returns
True if the terms unify, false otherwise.

This function implements the unification algorithm for Prolog-like terms. It handles variable dereferencing, variable binding, and unification of user-defined classes. When unifying a variable with a term, the variable is trailed before bind is called to ensure that the variable can be reset when backtracking occurs. When backtracking occurs , the trail is used to reset any variables that were bound after the call in which unify was called.

Parameters
t1The first term.
t2The second term.
trailThe trail for backtracking.
Returns
True if the terms unify, false otherwise.

Variable Documentation

◆ fail_pred

std::shared_ptr< FailPred > pl_search::fail_pred = std::make_shared<FailPred>(nullptr)

A shared pointer to a reusable failure predicate.