[m-dev.] Re: Character constants feature

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Dec 18 12:01:16 AEDT 1999


On 17-Dec-1999, Michael Day <mcda at cat.cs.mu.OZ.AU> wrote:
> 
> there appears to be a rather surprising feature in the precedence of
> character constants, to the effect that using '.' or '(' and possibly
> others will introduce syntax errors into code. These can be fixed by
> parenthising the character, ('.') etc,

Actually you don't need to parenthesize '('.
Only characters which are also operators, e.g. '.', '+', '*', etc.,
need to be parenthesized.

> but that is about as intuitive as a kick to the head.

The choice of a Prolog-like syntax has both advantages and
disadvantages ;-)

> Does it stem from the use of single quotes in quoting
> unusual identifiers, such as predicate names containing spaces?

Character literals are just identifiers whose length is one character.
Putting an identifier in single quotes does not prevent it from
being an operator.  For example, you can write

	incr(X, X '+' 1).

and this is perfectly valid Prolog (or Mercury) syntax.
So parentheses are needed if you want to use '+' as a character
rather than as an operator.

It wouldn't be too hard to change this, so that putting something
in single quotes prevented it from acting as an operator.
But that would make Mercury's syntax different from Prolog.
It's not clear that tweaking minor details like this one
would be worth it.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list