14.2 Logical goals (Ad)


On this page, we look at two logical goals:

  1. not
  2. fail


The not goal is logical negation. Its argument must be a goal. If the argument succeeds, the not goal fails. If the argument fails, the not goal succeeds.

For example,

?- not(eqv(54,47)).



This is because the eqv goal fails.

Note that you cannot use variable bindings that occurred inside the goal-argument after the not goal. For example, if you try to say:

?- not(eq(X,54)), eq(Y,X).

and expect Y to be bound to 54, you will be disappointed to see the answer:


This is because, although X is bound to 54 inside the first eq goal, the second eq goal is never executed. This is because the not goal fails, since the first eq goal succeeds.

Thus you cannot export any variable bindings occurring inside the argument to not after the not goal.


fail is the goal that always fails.

?- fail.

one usage of fail is to stop a computation that you know will not succeed. (However, the cut operator is often better for this).


Next, we look at some list goals.

Prev: 14.1 Relational goals (Ad)
Up: 14 Prolog+CG (Ad)
Next: 14.3 List goals (Ad)