[m-users.] Mercury operators explained

Zoltan Somogyi zoltan.somogyi at runbox.com
Wed Feb 19 09:30:01 AEDT 2014

On Tue, 18 Feb 2014 22:11:35 +0000, Piotr Trojanek <piotr.trojanek at gmail.com> wrote:

> Dear Mercury experts,
> please excuse me for a naive question, but where can I find
> documentation of the Mercury operators?
> I was translating my code from SWI-Prolog and found that there is no
> "=\=" operator in Mercury. There are many other built-in operators
> listed in the Mercury Reference Manual, but they are not explained.
> Am I missing something?
> -- Piotr
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://www.mercurylang.org/lists/listinfo/users

There is no =\= operator in Mercury, because there is no need for one.

In Prolog, the unification operator = operates on unevaluated terms. If you give it two
arithmetic expressions, it will tell you whether they have the same structure, but not
whether they evaluate to the same result. Arithmetic expressions are evaluated only
in special contexts, such as the operands of =\= or the right hand side of the "is" operator.

In Mercury, function calls (such as calls to the arithmetic functions) are evaluated wherever
they happen to be. So in Mercury, you use the usual equality operator = where in Prolog
you would use =\=.

Note that Mercury is NOT a Prolog dialect. Semantically, it is significantly different from
Prolog in several respects; this is one. Attempts to transliterate nontrivial Prolog programs
into Mercury won't work if the person doing the transliterating doesn't know the differences.

As for the list of operators in the Mercury language reference manual, some are built-in
constructs of the language, and are explained in the relevant section of that manual,
and some represent functions in the Mercury standard library, and are documented
in the library's reference manual.


More information about the users mailing list