# [mercury-users] Incomprehensible error output, even with -E.

Michael Richter ttmrichter at gmail.com
Thu Feb 2 16:01:25 AEDT 2012

On 2 February 2012 05:50, Julian Fondren <ayrnieu at gmail.com> wrote:

> to make the problem clearer, you have here
>
>   A = (func(X) = B, C),
>
> How is this not like your definitions of named functions?
>
>
It's got a lambda instead of a :- func body?

Maybe I'm fundamentally misunderstanding the syntax of funcs vs. preds.
(There doesn't appear to be a grammar for Mercury in the language
reference so I'm only inferring what's permitted and what's not.)

Let's say I have a predicate like this:

a(X,Y) :- Y = X.

This is fine, right?  And the equivalent written as a function is this:

a(X) = X.

I know this is fine because I've just tested it.  The compiler doesn't
vomit.  Now let's say that I want to do a calculation on X first.  Here
it'll be a brain-dead calculation but the principle is the same whether
it's something stupid like this or something that actually warrants
breaking out the calculation into its own sub-step:

a(X,Y) :- B = X * 2, Y = B.

Again, the compiler doesn't puke on this and the result is as expected.  So
the equivalent function is:

a(X) = B = X * 2, B.

Only that doesn't work because you get an operator precedence error on "=".
(It also looks pretty retarded.)  Time for plan B.

a(X) = (B = X * 2, B).

Whiiiiiiiiiiichâ€¦ gives me the error that's mystified me so long.  I may be
on to something here!  Let me take another crack at it.  Looking at the
library source I see another way that functions are defined.  Let me see if
the same kind of structure helps here.

a(X) = Y :- B = X * 2, Y = B.

OK, that works.  So let's see how that looks in a lambda.

A = (func(X) = Y :- B = X * 2, Y = B).

OK, that seems to work, so let's make B a func as well:

A = (func(X) = Y :-
B = (func(X) = Y :-
Y = X * 2
),
Y = B
).

Andâ€¦  Now I'm even more confused.  Yesterday when I tried that very
structure I got lots of whining from the compiler about syntax errors on
the :-. Damn.

Well, thanks for making me look at it more rigorously, Julian.  I don't
know why it broke when I first tried it that way, but at least this gets me
a step farther now!

--
"Perhaps people don't believe this, but throughout all of the discussions
of entering China our focus has really been what's best for the Chinese
people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20120202/03fc2769/attachment.html>