These predicates have the effect of controlling the execution flow of a Prolog demonstration.
call/1
call(G)
is true iff G
represents a goal
which is true. When G
contains !
as a
subgoal, the effect of !
shall not extend outside
G
.
Executing a call has the effect that (a) if G should fail, then the call will fail, and (b) G can be re-executed, and (c) any cut inside G is local to G.
Templates and modes for the predicate are as follows:
call(+callable_term)
Let's start with some simple tests verifying success of failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
call(!). | null | true |
Goal | Theory | success(String goal,String theory) |
---|---|---|
call(fail). false | null | false |
call((fail, X)). false | null | false |
call((fail, call(1))). | null | false |
b(_). | b(X) :- Y = (write(X), X), call(Y). a(1). a(2). | false |
b(3). | b(X) :- Y = (write(X), X), call(Y). a(1). a(2). | false |
Tests With Exception
Goal | Theory | success(String goal) | Type Of Error |
---|---|---|---|
call((write(3), X)). | null | true | |
call((write(3), call(1))). | null | true | |
call(X). | null | true | |
call(1). | null | true | |
call((fail, 1)). | null | true | |
call((write(3), 1)). | null | true | |
call((1 ; true)). | null | true |
(;)/2
(disjunction)';'(Either, Or)
is true iff Either
is
true or Or
is true.
Note that (;)/2
is re-executable.
Executing a disjunction has the effect that (a) if Either
shoud fail, then Or
will be executed on backtracking, and
(b) disjunction is transparent to cut.
Templates and modes for the predicate are as follows:
';'(goal, goal)
Note that ';'
is an predefined infix operator.
Let's start with some simple tests verifying success of failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
';'(true, fail). | null | true |
';'(!, call(3)). | null | true |
Goal | Theory | success(String goal,String theory) |
---|---|---|
';'((!, fail), true). | null | false |
Goal | Theory | Variable | Solution | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|
';'((X = 1, !), X = 2). | null | X | 1 | true |
','(';'(X = 1, X = 2), ';'(true, !)). | null | X | 1 | true |
(->)/2
(if-then)'->'(If, Then)
is true iff (1) If
is
true, and (2) Then
is true for the first solution of If
.
Note that (->)/2
is re-executable.
Executing an if-then has the effect that (a) if If
shoud fail, then if-then will fail, and (b) if If
should
succeed, then Then
will be executed, and (c) if If
should succeed and Then
later fails, the If
will not be re-executed because of the cut which has been executed, and
(d) the If
in an if-then is not transparent to cut, and
(e) a cut in Then
is transparent to if-then.
Templates and modes for the predicate are as follows:
'->'(goal, goal)
Note that '->'
is an predefined infix operator.
Let's start with some simple tests verifying success of failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
'->'(true, true). | null | true |
Goal | Theory | success(String goal,String theory) |
---|---|---|
'->'(true, fail). | null | false |
'->'(fail, true). | null | false |
Goal | Theory | Variable | Solution | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|
'->'(true, X = 1). | null | X | 1 | true |
'->'(';'(X = 1, X = 2), true). | null | X | 1 | true |
'->'(true, ';'(X = 1, X = 2)). | null | X | 1 | true |
'->'(true, ';'(X = 1, X = 2)). | null | X | 2 | true |
No error or exception is thrown by the engine while solving a
query with (->)/2
.
(;)/2
(if-then-else)(;)/2
serves two different functions depending on
whether or not the first argument is a compound term with functor (->)/2
.
';'('->'(If, Then), Else)
is true iff (1a) If
is true, and (1b) Then
is true for the first solution of If
, or
(2) If
is false and Else
is true.
Note that (;)/2
is re-executable. The cut prevents and
if-then-else from being re-executed a second time.
Executing an if-then-else has the effect that (a) if If
shoud fail, then if-then-else will be re-executed, and (b) if If
should succeed, then Then
will be executed, and (c) if
If
should succeed and Then
later fails, the
if-the-else will not be re-executed because of the cut which has been
executed, and (d) the If
in an if-then-else is not
transparent to cut, and (e) a cut in Then
is transparent
to Then
.
Re-executing an if-then-else has the effect that (a) the Else
will be executed, and (b) if Else
later fails, the
if-then-else will not be re-executed again because of the cut which has
been executed, and (c) a cut in Else
is transparent to Else
.
Templates and modes for the predicate are as follows:
';'('->'(goal, goal), goal)
Note that ';'
'->'
are predefined infix
operators so that (If -> Then ; Else)
is parsed as
';'('->'(If, Then), Else)
.
Let's start with some simple tests verifying success of failure of single goals.
Goal | Theory | success(String goal,String theory) |
---|---|---|
';'('->'(true, true), fail). | null | true |
';'('->'(fail, true), true). | null | true |
';'('->'((!, fail), true), true). | null | true |
Goal | Theory | success(String goal,String theory) |
---|---|---|
';'('->'(true, fail), fail). | null | false |
';'('->'(fail, true), fail). | null | false |
Goal | Theory | Variable | Solution | success(String goal,String theory,String variable,Strng solution) |
---|---|---|---|---|
';'('->'(true, X = 1), X = 2). | null | X | 1 | true |
';'('->'(fail, X = 1), X = 2). | null | X | 2 | true |
';'('->'(true, ';'(X = 1, X = 2)), true). | null | X | 1 | true |
';'('->'(true, ';'(X = 1, X = 2)), true). | null | X | 2 | true |
';'('->'(';'(X = 1, X = 2), true), true). | null | X | 1 | true |