[mercury-users] functions returning in values?

Fergus Henderson fjh at cs.mu.OZ.AU
Tue May 8 13:13:46 AEST 2001


On 07-May-2001, Terrence Brannon <princepawn at earthlink.net> wrote:
> I was meandering through the Mercury source files and
> somewhere came across something like this:
> 
> :- func g(int) = int.
> :- mode g(out) = in.
> 
> In other words, it takes and _out_ mode variable as its argument and
> _returns_ and in mode value... If you could help me out, I would like
> to know how one might call such a function

Just use a call to the function where the function result is already bound
(e.g. to a constant), and the function argument is a fresh variable.
For example:

	main -->
		{ g(X) = 42 },
		print("solution to g(X) = 42 is X = "), print(X), nl.

> and I am a bit confused as to when such a mode setup would be advantageous. 

Generally it is most useful when you have more than one mode for a function.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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