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.
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.
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
(The address of Mercury data structures that have been passed to
C via the foreign language interface are guaranteed to be appropriately