[m-users.] Any way to write . or : as a character literal?

Zoltan Somogyi zoltan.somogyi at runbox.com
Sun Dec 6 15:11:59 AEDT 2020



On Sat, 5 Dec 2020 22:51:52 -0500, "Jeremy W. Sherman" <jeremyw.sherman at gmail.com> wrote:
> Since character literals are the same as single-character quoted
> names, is there any way to escape or write either of these outside of
> a circumlocution like `det_from_int(0':)`?

Yes, there is:

    Char = ('.')

Basically, if a character is an operator, you need to put parentheses
around them, even if you have already put single quotes around them.
Basically, if x is an operator, then the scanner/parser consider 'x' to be
an operator as well. The parentheses say there is nothing to apply
the operator to.

I just checked: it seems the language reference manual does not
explicitly talk about the need for parentheses in such cases. I will fix that.

The need for () is an unfortunate side effect of reusing the syntax rules of Prolog
for Mercury. That decision is a lot less useful now than it was when
Mercury was just starting out, but its less-than-nice effects are not important
enough to fix with a backward-compatibility-breaking change. The Mercury
community is small enough; we don't want to break it in half, as Python 3 did
for its community.

Zoltan.


More information about the users mailing list