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

Represents the equivalent of Prolog's once(Pred). The aim is to remove any choicepoints produced by Pred. More...

#include <pred.hpp>

Inheritance diagram for pl_search::Once:
Inheritance graph
[legend]
Collaboration diagram for pl_search::Once:
Collaboration graph
[legend]

Public Member Functions

 Once (Trail *trail, PredPtr pred)
 Constructs a Once predicate with the given trail and predicate.
 
bool call () override
 Calls the once predicate.
 
- Public Member Functions inherited from pl_search::Pred
 Pred (Trail *trail)
 Default constructor.
 
PredPtr get_continuation ()
 Gets the continuation of the predicate.
 
virtual void set_continuation (PredPtr cont)
 Sets the continuation of the predicate.
 
PredPtr last_pred ()
 Follows the continuation chain to the last predicate.
 
virtual void call_init ()
 Initialize call.
 
bool call_continuation ()
 Calls the continuation of the predicate - first call_init and then call.
 
virtual ~Pred ()=default
 Virtual destructor for proper cleanup.
 
virtual std::string get_name ()
 For debugging.
 

Protected Attributes

PredPtr pred
 
- Protected Attributes inherited from pl_search::Pred
PredPtr continuation
 The continuation of the predicate.
 
Trailtrail
 Pointer to the trail for managing variable bindings.
 

Detailed Description

Represents the equivalent of Prolog's once(Pred). The aim is to remove any choicepoints produced by Pred.

The meta-predicate Once is used to remove any choicepoints produced by Pred. If Pred succeeds then the continuation is called and any choicepoints produced by Pred are removed. If Pred or the continuation fails then the Once predicate fails and any bindings produced by Pred are undone. Note that Pred is a local call - i.e. its continuation is not related to the continuation of the Once predicate. Also note that Pred could be a conjunction of predicates.

Constructor & Destructor Documentation

◆ Once()

pl_search::Once::Once ( Trail trail,
PredPtr  pred 
)
inline

Constructs a Once predicate with the given trail and predicate.

Parameters
trailPointer to the trail.
predThe predicate called within the once.

Member Function Documentation

◆ call()

bool pl_search::Once::call ( )
overridevirtual

Calls the once predicate.

Returns
True if the predicate succeeds and the continuation succeeds, false otherwise, removing any choicepoints produced by the predicate.

When a Once object is called it calls the predicate supplied to the Once constructor. If the call fails then the Once predicate fails and any bindings created by the call are undone. If the call succeeds then the continuation is called. Note that no alternative choices for pred are tried if the continuation fails. The Once predicate is used to remove any choicepoints produced by pred.

Reimplemented from pl_search::Pred.

Member Data Documentation

◆ pred

PredPtr pl_search::Once::pred
protected

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