[mercury-users] Field updates and state variables
Mark Brown
mark at cs.mu.OZ.AU
Mon Jul 3 13:15:49 AEST 2006
On 02-Jul-2006, Peter Hawkins <hawkinsp at cs.stanford.edu> wrote:
> Hi..
> On Jul 2, 2006, at 7:26 PM, Peter Schachte wrote:
>
> >On Sun, Jul 02, 2006 at 12:28:06PM -0700, Peter Hawkins wrote:
> >>Hi...
> >>
> >>I find myself writing code like this a lot:
> >>...
> >>!:S = !.S ^ my_map := map.insert(!.S ^ my_map, Key, Value)
> >>...
> >>
> >>Wouldn't it be nice if I could write the field update as:
> >>map.insert(Key, Value, !S ^ my_map)
> >
> >That seems pretty magical; the former is not what I would naturally
> >expect the latter to expand to.
>
> Well, to be precise I actually meant it to expand to this:
> map.insert(Key, Value, !.S ^ my_map, Temp),
> !:S = !.S ^ my_map := Temp,
>
> This hopefully is more obvious. I'm open to something like the elem
> trick --- I just want a little less typing for updating objects
> inside state variables.
See the module svmap in the standard library (and other modules named sv*).
Cheers,
Mark.
--------------------------------------------------------------------------
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