[m-rev.] For review: State-variable record update transformation

Peter Schachte schachte at csse.unimelb.edu.au
Tue Mar 6 14:25:21 AEDT 2007

Ralph Becket wrote:

> (1)
> 	!Pos ^ x := 7,
> 	!Pos ^ y := 42
> <=>
> 	!:Pos = !.Pos ^ x := 7,
> 	!:Pos = !.Pos ^ y := 42
> You are proposing that
> (2)
> 	!Pos := position(7, 42)
> <=>
> 	!:Pos = position(7, 42)
> In (1), there is a connection between the original and final states of
> Pos; in (2) there is not.

There's no connection in either case, because all the data has been replaced.

> If we were to pinch their syntax we would also be able to pass !X where
> a single argument is expected.  How could this be made to work?

A state variable is not an ordinary value in Mercury; you can't use it the same
ways you can use an ordinary variable.  Think of it as a changeable value.
When you pass it as an argument to a predicate, it's like an "in out" parameter
in Ada; in Mercury, this is implemented as two ordinary arguments.  !X := Term
means change the current value of !X to be Term.  !X ^ f is also a changable
term; !X ^ f := Term means change the f field of !X to be Term.  When you want
to specify the current value of !X, you write !.X.  You can also write !:X to
specify the next value of !X, though I think the !X := Term syntax is better
than !:X = Term.  For one thing, the latter is a mess if !:X appears in Term,
while you wouldn't expect to be able to put !X in Term because you can never
put !X in a term.  Ie, you can get into trouble by using !:X, but never by
using !X := without !:X.

It is a consistent story, and I think it's easier to reason about than always
thinking of it in terms of pairs of variables.

Peter Schachte              You can fool all of the people some of the time;
schachte at cs.mu.OZ.AU        you can fool some of the people all of the time,
www.cs.mu.oz.au/~schachte/  but you can't fool all of the people all of the
Phone: +61 3 8344 1338      time. -- Abraham Lincoln
mercury-reviews mailing list
Post messages to:       mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions:          mercury-reviews-request at csse.unimelb.edu.au

More information about the reviews mailing list