[m-dev.] for review: transformation of x `fun` y to fun(x,y)

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Jul 9 18:21:09 AEST 1999


On 09-Jul-1999, Peter Ross <petdr at cs.mu.OZ.AU> wrote:
> 
> Allow the term (x `fun` y) to be transformed to fun(x,y).
> 
> library/lexer.m:
>     Handle the backquote token.
> 
> library/parser.m:
>     Do the term transformation as the program is parsed.
> 
> doc/reference_manual.texi:
>     Document the new behaviour.

You should mention this in NEWS and in w3/news/newsdb.inc.

> Index: doc/reference_manual.texi
>  Tokens in Mercury are the same as in ISO Prolog.
> -The only difference is the @samp{#@var{line}} token, which
> -is used as a line number directive (see below).
> +The only differences are the @samp{#@var{line}} token, which
> +is used as a line number directive (see below) and the @samp{`} token.

@samp{`} comes out as ``', which is rather ugly, so
I suggest s/@samp{`}/backquote (`) token/

(You should also document the backquote token, but the current documentation
for "name" tokens reference manual is incomplete, and so the place where you
should add the documentation for the backquote token is currently missing.
So don't worry about that.  Sometime soonish I will fix that so that it
documents graphic token names and backquote names.)

>  The different tokens are as follows.  Tokens may be separated by
>  whitespace or line number directives.
> @@ -294,8 +294,9 @@
>  @section Terms
>  
>  Syntactically, terms in Mercury are exactly the same as in ISO Prolog,
> -except that as an extension we permit higher-order terms, as described
> -below.
> +except that as extensions we permit higher-order terms and the
> +introduction of infix operators by the use of grave accents (backquotes)
> +, as described below.
>  However, the meaning of some terms in Mercury is different to that
>  in Prolog.  @xref{Data-terms}.
>  
> @@ -309,6 +310,13 @@
>  a sequence of argument terms separated by commas, and a close
>  parenthesis.  Compound terms may also be specified using
>  operator notation, as in Prolog.
> +
> +Operators can also be formed by enclosing an identifier between grave
> +accents (backquotes).  Any variable or constructor may
> +be used as an operator in this way.  If @code{fun} is an identifier,
> +then a term of the form @code{fun(x,y)} is equivalent to 
> +code{x `fun` y}.  The operator is treated as having the highest precedence
> +possible and is left associative.

I think the equivalence would be clearer if you stated it the other way
around, i.e.

	a term of the form code{x `fun` y} is equivalent to @code{fun(x,y)}

rather than

	a term of the form @code{fun(x,y)} is equivalent to code{x `fun` y}

Also

	s/constructor/name/
	s/identifier/variable or name/
	s/fun/@var{fun}/
	s/code/@code/

Apart from that, this looks fine.

-- 
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