[m-users.] String comparison when compiling to C

Zoltan Somogyi zoltan.somogyi at runbox.com
Fri Aug 23 21:35:34 AEST 2024



On Fri, 23 Aug 2024 12:15:24 +0100, "Sean Charles (emacstheviking)" <objitsu at gmail.com> wrote:
> % The builtin comparison operation on strings is also implementation
> % dependent. The current implementation performs string comparison using
> %
> % - C's strcmp() function, when compiling to C;

> So what is the 'way' to do string comparisons?

The compare predicate in the builtin module. That is what your initial quote
is referring to.

> I find it odd in all the code I've written, I have never needed to do this before!

Most of the time, when people compare strings in other languages,
they do it to implement operations such as maps from strings to other entities,
or sorting. In Mercury, the standard library provides all the usual such operations.
And since those operations are generic, i.e. they operate on values of any type,
their implementations use the generic compare predicate in the builtin module,
not type-specific operations such as < or >.

Zoltan.




More information about the users mailing list