« Return to Thread: strange behaviour of compare/3

Re: strange behaviour of compare/3

by Ulrich Neumerkel :: Rate this Message:

Reply to Author | View in Thread

Simon Strobl writes:
>                                                                          It
>would never have occurred to me that compare(>, 1, 1.0) is true.
 
>Does this really have to be true? Maybe there are good reasons why this
>should be so. But then a word of warning in the manual entry of compare/3
>would be very useful.
 
compare/3 is a compact way to get the functionality of @< == etc.
ISO Term order (13211-1:7.2) is a total ordering of all kinds of
terms, including variables.  Even X and 3.0 compare - i.e. there is no
instantiation error in X @< 3.0 but there is one in X < 3.0.
 
The ordering is: variables, floats, integers, atoms, compounds.
 
In any case: This kind of ordering is probably not the one you want,
if you expect compare(=, 1, 1.0) to be true.
 
You probably would like to have some numcompare/3 defined with =:= and
<, yielding an instantation error for numcompare(R, 1, X).
Maybe even evaluating its arguments?
_______________________________________________
SWI-Prolog mailing list
SWI-Prolog@...
https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog

 « Return to Thread: strange behaviour of compare/3