can't do simple division with / operator
kc0olm, Mar 24. 2017, 14:27
What is the operator for simple division? 3 is 6/2. returns false, as do any such queries
Re: can't do simple division with / operator
Jan Burse, Mar 27. 2017, 02:14
Yes the following is correct ISO conforming behaviour:
?- 3 is 6/2.
The reason is simple, (/)/2 returns always a float value(*), and the present case it gives 3.0. But during term unification float values are different from integer values, here 3.
You can instead do the following and use another ISO predicate:
?- 3 =:= 6/2.
The predicate (=:=)/2, in contrast to term unification, is able to compare integers and floats, and should be used in number comparison.
(*) SWI-Prolog returns integer when it can so, but this
is not required by the ISO core standard.