These predicates are simply derived from the control constructs and provide additional facilities for affecting the control flow during execution.
\+/1 (not provable)'\\+'(Term) is true iff call(Term) is false.
Templates and modes for the predicate are as follows:
'\\+'(@callable_term)
Note that \+ is a predefined operator.
Let's start with some simple tests verifying success or failure of single goals.
| alice.tuprolog.SimpleGoalFixture | |
| goal | success() |
| '\\+'(true). | false |
| \+(!). | false |
| '\\+'((!, false)). | true |
| '\\+'(4 = 5). | true |
| \+(X = f(X)). | |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
| fit.ActionFixture | |
| start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
| fit.ActionFixture | ||
| enter | query | (X=1; X=2), \+((!, fail)). |
| check | hasSolution | true |
| enter | variable | X |
| check | binding | 1 |
| check | hasAnotherSolution | true |
| enter | variable | X |
| check | binding | 2 |
The remaining tests cover the cases when an error or exception is thrown by the engine while solving a query.
| alice.tuprolog.PrologActionFixture | ||
| enter | query | \+(3). |
| check | hasSolution | false |
| check | exception | type_error(callable, 3) |
| enter | query | '\\+'(X). |
| check | hasSolution | false |
| check | exception | instantiation_error |
once/1once(Term) is true iff call(Term) is true.
once(Term) behaves as call(Goal) but it is not re-executable.
Templates and modes for the predicate are as follows:
once(+callable_term)
Let's start with some simple tests verifying success or failure of single goals.
| alice.tuprolog.SimpleGoalFixture | |
| goal | success() |
| once(!). | true |
| once(repeat). | true |
| once(fail). | false |
| once(X = f(X)). | |
Now we run some tests also verifying the unification for some of the variables in goals.
First of all, let's start an appropriate fixture containing an engine.
| fit.ActionFixture | |
| start | alice.tuprolog.EngineFixture |
Then, ask the engine to solve a query, and check variable bindings.
| fit.ActionFixture | ||
| enter | query | once(!), (X=1; X=2). |
| check | hasSolution | true |
| enter | variable | X |
| check | binding | 1 |
| check | hasAnotherSolution | true |
| enter | variable | X |
| check | binding | 2 |
Note that there are no tests covering the cases when an error or exception is thrown by the engine while solving a query using this predicate.
repeat/0repeat is true.
Templates and modes for the predicate are as follows:
repeat
Note that repeat is re-executable.
Let's start with some simple tests verifying success or failure of single goals.
| alice.tuprolog.SimpleGoalFixture | |
| goal | success() |
| repeat, !, fail. | false |
Run the tests!
The results of the tests for Logic and control are as follows:
| fit.Summary |