pl_search_cpp 2.1
Loading...
Searching...
No Matches
Public Member Functions | Protected Attributes | Friends | List of all members
pl_search::Trail Class Reference

The Trail class is used to manage variable bindings during the execution of Prolog-like predicates. More...

#include <trail.hpp>

Public Member Functions

void trail_var (PVarPtr v)
 Trails a variable.
 
void unbind_to (int index)
 Unbind (reset) variables back to a certain point in the trail.
 
int size () const
 Returns the number of trail entries in the trail (top of stack)
 
PVarPtr top ()
 

Protected Attributes

std::stack< std::shared_ptr< trail_entry > > trail_stack
 The stack of trail entries.
 

Friends

class TailTest
 

Detailed Description

The Trail class is used to manage variable bindings during the execution of Prolog-like predicates.

The trail maintains a stack of trail entries, where each entry represents a variable and its previous value. When a variable is bound to a new value, it is trailed by pushing a trail entry onto the stack. When backtracking occurs, the trail is used to unbind variables back to a certain point, restoring their previous values. During execution the choicepoint created by non-deterministic predicates determines the point (trail index) to which variables are unbound when backtracking occurs. If the user program does repeated searches then the program should call unbind_to(0) to reset all variables back to their initial values before starting the next search. Even if the user program does a complete search there may be variables that are still bound at the end of the search. This can happen either because the user program can determine some initial variable bindings before the first predicate call is made or because the initial predicates in the call chain are deterministic.

Member Function Documentation

◆ size()

int pl_search::Trail::size ( ) const
inline

Returns the number of trail entries in the trail (top of stack)

Returns
The number of trail entries.

◆ top()

PVarPtr pl_search::Trail::top ( )
inline

◆ trail_var()

void pl_search::Trail::trail_var ( PVarPtr  v)
inline

Trails a variable.

Parameters
vThe variable to trail.

◆ unbind_to()

void pl_search::Trail::unbind_to ( int  index)
inline

Unbind (reset) variables back to a certain point in the trail.

Parameters
indexThe index to unbind variables back to.

Friends And Related Symbol Documentation

◆ TailTest

friend class TailTest
friend

Member Data Documentation

◆ trail_stack

std::stack<std::shared_ptr<trail_entry> > pl_search::Trail::trail_stack
protected

The stack of trail entries.


The documentation for this class was generated from the following file: