2
votes

The Prolog standard ISO/IEC 13211-1:1995/Cor.2:2012 features compare/3:

8.4.2 compare/3 – three-way comparison

8.4.2.1 Description

compare(Order, X, Y) is true iff Order unifies with R which is one of the following atoms: '=' iff X and Y are identical terms (3.87), '<' iff X term_precedes Y (7.2), and '>' iff Y term_precedes X. [...]

Recently, it dawned on me that using the atoms <, =, and > is somewhat weird:

  • The predicates (<)/2 and (>)/2 express arithmetic comparison.

  • The predicate (=)/2 on the other hand is syntactic term unification.

IMHO, a much more natural choice would (have) be(en) @<, == and @>, as these are exactly the predicates whose fulfillment is determined by compare/3.

So: why were the atoms </=/> chosen—and not @</==/@>?

2
Looks like a rule for a linter.Guy Coder
@GuyCoder. In most cases, yes. But that cuts quite some corner cases (when the result is input/output/not directly used). And potentially breaking existing code is a no-no:)repeat
A linter rule does not always mean it is a bug or error, it can can also mean it is something worthy of a second look and most decent linters allow you to turn off the rules globally or for specific instance or even modify some of the rules.Guy Coder

2 Answers

3
votes

Recently, it dawned on me that using the atoms <, =, and > is somewhat weird:

The compare/3 predicate existed in several Prolog systems prior to find its way into the ISO Prolog Core standard. The choice here (I was the WG17 Core editor at the time) was to preserve backward compatibility.

2
votes

compare/3 exists as a built-in since 1982 which is the quasi second edition of the DECsystem 10 manual. The first of 1978 (called User's guide) did not contain compare/3 nor (@<)/2 and related built-ins; only (==)/2 and (\==)/2. The 1982 manual refers in the definition of this built-in to a "standard order". And thus the three symbols (which constitute in the standard the domain order) make quite some sense in that context. The standard itself refers to 7.2 Term order via term_precedes.

Some systems had used == as the symbol for identity, but changed to =. However, I have never encountered @< in any system.

Note that identity of terms is well defined even when considering terms with variables and even infinite trees, whereas the general Term order is only partially defined in such cases.