[mercury-users] destructive update?
Barney Fisher
barney.fisher at googlemail.com
Fri Jul 13 02:55:42 AEST 2007
On 09/07/07, Mark Brown <mark at csse.unimelb.edu.au> wrote:
> On 09-Jul-2007, Barney Fisher <barney.fisher at googlemail.com> wrote:
> > Assuming that destructive update is a must, how should I approach
> > implementing destructive update on terms of a Mercury type? via the
> > foreign language interface?
>
> It is difficult to access Mercury types from foreign code in a portable
> way, so I wouldn't recommend this approach. A portable way is to use
> the store module:
>
> update_node_arg(Node0, ArgNum, NewVal, Node) :-
> some [!S] (
> store.new(!:S),
> store.new_ref(Node0, Ref, !S),
> store.arg_ref(Ref, ArgNum, ArgRef, !S),
> store.set_ref_value(ArgRef, NewVal, !S),
> store.extract_ref_value(!.S, Ref, Node)
> ).
>
> Node is Node0 with the ArgNum'th argument replaced by NewVal.
> Operationally, Node occupies the same location that Node0 had (note that
> Node0's mode is `di').
>
> Cheers,
> Mark.
Thanks for the response Mark, it has been very useful. I have a
question though. The store documentation says the output of
extract_ref_value, in this case Node, has mode out. Why is this? I
would have expected it to have mode uo because everything input to the
store has mode di, and the store itself is even destroyed after this
call, so I can't see why Node is not unique.
Thanks
Barney
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list