[ Control | Reference Manual | Alphabetic Index ]

~ +Goal

The sound negation operator. If Goal is not ground, the predicate delays.
Goal
Callable term or a variable.

Description

This is the sound negation operator. It can be used instead of not/1, or \+/1 (the negation as failure operators). It is known that negation as failure may yield non-logical results if the Goal contains free variables. To avoid this, ~/1 delays if Goal is not ground. If the free variables are bound later in the execution, the delayed predicate is woken and executed and may yield success or failure. While ~/1 always behaves logically, in some cases it delays where negation as failure or constructive negation would have immediately (and correctly) failed.

Modes and Determinism

Modules

This predicate is sensitive to its module context (tool predicate, see @/2).

Fail Conditions

Fails if Goal can be satisfied

Examples

Success:
    ~ 3 = 4.
    ~ 3 = X,            (delays ...
        X = 4.             ... and succeeds with X = 4)
Fail:
    ~ 3 = 3.
    ~ 3 = X,            (delays ...
        X = 3.             ... and fails)
    ~ X = X,            (delays ...
        X = 3.             ... and fails)



See Also

not / 1, \+ / 1, suspend / 3