[mercury-users] Uniqueness modes etc

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Dec 30 19:06:52 AEDT 2003


On 30-Dec-2003, Dr Mark H Phillips <mark at austrics.com.au> wrote:
> I think I'm misunderstanding something, which I probably should try and
> clarify before going any further.  From your reply to my original
> email:
> 
> [Fergus Henderson:]
> > [Dr Mark H Phillips:]
> > > Is it possible to have a variable, x say, and send it into a
> > > function using the di mode, and extract it out again using 
> > > the uo mode?
> > 
> > Yes.
> 
> I thought you meant that I could do this:
> 
>   :- pred r(int, int, int, int).
>   :- mode r(di, uo, in, out) is det.
>   r(X, Y, N, Fn) :- ....
>   ...
>   r(X_0, X_0, N, Fn)
> 
> meaning that there are two versions of X_0, the first with 
> scope up until the evaluation of r, and the second with 
> scope starting immediately after the evaluation of r.

No.  I meant that you can have a variable, say "X", and you can send it
into a function using the di mode, and you can extract the new value
out again using the uo mode.  But you can't call the new value "X" --
it has to have a different name.  The usual convention is to call the
first value "X0", the next one "X1", and so on, with the final value
being called just "X".

Another alternative is to use state variable notation.
With state variable notation, you can write e.g.

	p(X, ...) :-
		r(!X, N, Fn),
		r(!X, AnotherN, AnotherFn).

and this will be treated as an abbreviation for

	p(X0, X2, ...) :-
		r(X0, X1, N, Fn),
		r(X1, X2, AnotherN, AnotherFn).

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  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