[mercury-users] Prev code modified

Ralph Becket rafe at cs.mu.OZ.AU
Mon Oct 14 16:49:25 AEST 2002


Noel  Pinto, Monday, 14 October 2002:
> 
> main-->
>         print("Enter an int: "), flush_output,
>         read_int(Int),
>         print("The Square is : "), print(numSqr__numSqre(Int)), 
> nl.

...

> numSqre(N,S):-
>         ( if N = 0 then
>                 S = 0
>         else
>                 S = N * N
>         ).

...

> $ ./read_int
> Enter an int: 12
> The Square is : '<<predicate>>'

numSqre/2 is a *predicate* with two arguments.  Your call to 
numSqr__numSqre(Int) only passes one argument, hence this expression is
a closure (i.e. a partial application of a predicate.)  The Mercury
run-time doesn't know how to print out closures properly, so it just
writes `<<predicate>>'.

You need to rewrite numSqre/2 as a single-argument function and all will
be well.

If you use io__write_string and io__write_int, you will get much clearer
error messages from the compiler.  The problem is that io__print will
print anything, so the compiler can't know anything about what you're
trying to achieve.

- Ralph
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list