Jake Badlands
Jake Badlands

Reputation: 1026

Simple: how to make the test for a false case?

The test should returns true: if the first part is true, and the second part is false.

Tried to do something like that:

f_test  :- f(x), % 1st part
           f(y) is false. % 2nd part

But it gives me an error:

ERROR: is/2: Arithmetic: `false/0' is not a function.

Please tell me, how to do it correctly?

Upvotes: 2

Views: 6879

Answers (2)

m09
m09

Reputation: 7493

(is)/2 is a predicate intended to perform arithmetic. Even if your test was about arithmetic, the use of (=:=)/2 would be preferred (because (is)/2 is used to instantiate a variable. When you use it to check a variable value, you misuse it. OTOH, (=:=)/2 is used to compare numbers).

But here your test isn't about arithmetic, it's about knowing if something is true or not. There is an operator for that, which checks if a given term is provable or not, it's (\+)/1, use is:

f_test :-
    f(x),
    \+ f(y).

Upvotes: 5

joel76
joel76

Reputation: 5675

You can try

f_test :- f(x), \+f(y).

Upvotes: 1

Related Questions