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, !.
Here are the trees:
P
)P
succeeds:P
fails:P
succeeds:Behaviour is exactly the same as for the First Program, exit the whole predicate with Failure.
P
fails:Note that not/1
is already a built-in, but I guess we can override it for this exercise.
?- [user].
|: not(P) :- P, !, fail.
|: not(P).
Warning: user://1:9:
Warning: Singleton variables: [P]
|: % user://1 compiled 0.02 sec, 2 clauses
true.
Okay
?- not(true).
false.
?- not(false).
true.
Looks good.
?- [user].
|: not(P) :- P, !, fail.
|: not(P) :- P, !.
|: % user://1 compiled 0.02 sec, 2 clauses
true.
?- not(true).
false.
?- not(false).
false.
Looks good.