Download SICStus Prolog User`s Manual

Transcript
134
SICStus Prolog
In sicstus execution mode no cuts are allowed in P. In iso execution mode
cuts are allowed in P and their scope is the goal P.
Remember that with prefix operators such as this one it is necessary to be
careful about spaces if the argument starts with a (. For example:
| ?- \+ (P,Q).
is this operator applied to the conjunction of P and Q, but
| ?- \+(P,Q).
would require a predicate \+ /2 for its solution. The prefix operator can however
be written as a functor of one argument; thus
| ?- \+((P,Q)).
is also correct.
+P -> +Q ; +R
[ISO]
Analogous to
if P then Q else R
and defined as if by
(P -> Q; R) :- P, !, Q.
(P -> Q; R) :- R.
except the scope of any cut in Q or R extends beyond the if-then-else construct.
In sicstus execution mode no cuts are allowed in P. In iso execution mode
cuts are allowed in P and their scope is the goal P.
Note that this form of if-then-else only explores the first solution to the goal P.
Note also that the ; is not read as a disjunction operator in this case; instead,
it is part of the if-then-else construction.
The precedence of -> is less than that of ; (see Section 4.6 [Operators], page 51),
so the expression is read as
;(->(P,Q),R)
[ISO]
+P -> +Q
When occurring as a goal, this construction is read as equivalent to
(P -> Q; fail)
if(+P,+Q,+R)
Analogous to
if P then Q else R
but differs from P -> Q ; R in that if(P, Q, R) explores all solutions to the
goal P. There is a small time penalty for this—if P is known to have only one
solution of interest, the form P -> Q ; R should be preferred.
In sicstus execution mode no cuts are allowed in P. In iso execution mode
cuts are allowed in P and their scope is the goal P.
once(+P)
[ISO]
Finds the first solution, if any, of goal P. Fails if no solutions are found. Will
not explore further solutions on backtracking. Equivalent to
(P -> true; fail)