Next: Function trailing, Previous: Choice points, Up: Trailing [Contents]
The simplest form of trailing is value trailing. This allows you to trail updates to memory and have the Mercury runtime engine automatically undo them on backtracking.
MR_trail_value()
Prototype:
void MR_trail_value(MR_Word *address, MR_Word value);
Ensures that if future execution backtracks to the current choice point, then value will be placed in address.
MR_trail_current_value()
Prototype:
void MR_trail_current_value(MR_Word *address);
Ensures that if future execution backtracks to the current choice point, the value currently in address will be restored.
‘MR_trail_current_value(address)’ is equivalent to ‘MR_trail_value(address, *address)’.
Note that address must be word aligned
for both MR_trail_current_value()
and MR_trail_value()
.
(The address of Mercury data structures
that have been passed to C via the foreign language interface
are guaranteed to be appropriately aligned.)