[mercury-users] destructive update?

Mark Brown mark at csse.unimelb.edu.au
Tue Jul 10 04:07:51 AEST 2007


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.

--------------------------------------------------------------------------
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