What does the following code do?
not(P) :- P, !, fail.
not(P).
And how does that work differently from the following 2 codes :
not(P) :- P, !, fail.
not(P) :- P, !.
What does the following code do?
not(P) :- P, !, fail.
not(P).
And how does that work differently from the following 2 codes :
not(P) :- P, !, fail.
not(P) :- P, !.
Copyright © 2021 Jogjafile Inc.
Here are the trees:
First Program (inverses the success value of
P)If the call to
Psucceeds:If the call to
Pfails:Second Program (always fails)
If the call to
Psucceeds:Behaviour is exactly the same as for the First Program, exit the whole predicate with Failure.
If the call to
Pfails:Trying Program 1
Note that
not/1is already a built-in, but I guess we can override it for this exercise.Okay
Looks good.
Trying Program 2
Looks good.