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

Mark Brown mark at csse.unimelb.edu.au
Thu Feb 2 19:30:52 AEDT 2012

Hi Michael,

On 02-Feb-2012, Michael Richter <ttmrichter at gmail.com> wrote:
> Code is:
> main(!IO) :-
>     N = (func(X) = ((func) = X)),
>     A = (func(K, X1, X2, X3, X4, X5) =
>             (B = ((func) = apply(A, K - 1, B, X1, X2, X3, X4))),
>             (K =< 0 ->
>                 apply(X4) + apply(X5)
>             ;
>                 apply(B)
>             )

"A, B" means conjunction (a goal), not execute A then return B (an expression).
The construct you are looking for is

    Head = Result :- Body

which is covered in sections 2.8 and 2.13.5 of the reference manual.

>         ),
>     io.write_int(apply(A, 10, apply(N, 1), apply(N, -1), apply(N, -1),
> apply(N, 1), apply(N,0)), !IO),
>     io.write_string("\n", !IO).
> (The line number for main/2 is 28.)
> Errors generated from this:
> man_or_boy.m:030: In clause for predicate `main'/2:
> man_or_boy.m:030:   error: the language construct `,'/2 should be used as a
> man_or_boy.m:030:   goal, not as an expression.

That's the error - you've used it where an expression was expected.
The line number is misleading - line 30 is where the term starts, but the
comma itself is actually on line 31.

> man_or_boy.m:030:   If you are trying to use a goal as a boolean function,
> you
> man_or_boy.m:030:   should write `if <goal> then yes else no' instead.

To this mmc -E could add

    If you are trying to write a function with a body, you should write
    `<head> = <result> :- <body>'.

> man_or_boy.m:031: In clause for predicate `main'/2:
> man_or_boy.m:031:   in argument 1 of clause head:
> man_or_boy.m:031:   error: the language construct `='/2 should be used as a
> man_or_boy.m:031:   goal, not as an expression.

This is spurious, but since the code doesn't match either a function fact
or a function rule, mmc treats it as a unification.  Again, mmc -E could
mention functions with bodies.

> man_or_boy.m:031: In clause for predicate `main'/2:
> man_or_boy.m:031:   in argument 2 of functor `,/2':
> man_or_boy.m:031:   error: undefined symbol `+/2'.

This error, and similar ones, tells you that you haven't imported the int

> If I replace the entire body of the lambda assigned to A with, say, 67 or
> an apply(X1) I have no problems (aside from warnings about unused
> variables).
> How can I do what I want to do?

Do you mean get your code to compile, or comprehend the error messages?
For the latter, I recommend taking the messages one at a time starting
from the first, and looking at the piece of code it refers to.


mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list