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 expected false actual |
'\\+'(4 = 5). | true expected false actual |
\+(X = f(X)). | true |
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/1
once(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)). | false |
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/0
repeat
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 | |
counts | 16 right, 2 wrong, 2 ignored, 0 exceptions |
input file | D:\Silvia\Merge_Tesi\Tesi\test\logicAndControl.html |
input update | Tue Dec 23 03:02:00 CET 2008 |
output file | D:\Silvia\Merge_Tesi\Tesi\test\report_Montanari\logicAndControl.html |
run date | Wed Sep 28 12:47:48 CEST 2011 |
run elapsed time | 0:00.52 |