[mercury-users] Mercury Math Logarithms

Nancy Mazur Nancy.Mazur at cs.kuleuven.ac.be
Tue Oct 22 17:45:08 AEST 2002


* Noel  Pinto <cool4life at rediffmail.com> [2002-10-22 09:40]:
> Hi,
> 
> I am trying to have a number and find out the square root for it. 
> I have written a code as below...
> 
> :- module log_sqrt.
> :- interface.
> :- import_module io.
> :- pred main(io__state, io__state).
> :- mode main(di, uo) is det.
> 
> :- implementation.
> :- import_module math, float.
> 
> main -->
>         print(" Square root of 9 is \n"),
>         math__sqrt(9.00).

In your previous examples you didn't make that mistake though... 
Look up the documentation of print, and you'll see that it takes three
arguments. Never wondered why you only write one argument when you use
it here? This is because of the DCG notation that you are (without
knowing it perhaps) using. 
Now look up the documentation for math__sqrt. It has clearly arity 1,
and it doesn't have _anything_ to do with IO, or bringing any results
to stdout. That's why it needs to be wrapped between "{" and "}". 
Check out the documentation on DCG. 

The solution: 

main -->
        print(" Square root of 9 is \n"),
        { Res = math__sqrt(9.00) }, 
	io__write_float(Res).

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