[m-dev.] Trailing
Peter Schachte
pets at students.cs.mu.oz.au
Tue Aug 12 17:56:30 AEST 1997
On Mon, 11 Aug 1997, Fergus Henderson wrote:
> Yes, I think it is likely that _some_ form of exception handling will
> become part of the Mercury language and/or the Melbourne implementation.
> For example, adding io__throw and io__catch would be fairly simple and
> wouldn't compromise the semantics.
But those, if I correctly guess their semantics, wouldn't call for
untrailing to be done, so they wouldn't call MR_cut_to_choicepoint().
There is another interesting issue relating to trailing, exception handling,
and semidet code. As we well know, it may be necessary to trail changes
even in a det context, in case an exception forces changes to be undone.
For example (I'll use Quintus exception handling syntax, because I know it):
on_exception(X,
(mangle_array(A0, A1),checkit(A1)),
do_something_with(A0, X))
where checkit can raise an exception. Of course, it's undesirable to
require trailing every destructive change in every context in which an
exception can happen. This is the can of worms (are there any
others?) that is opened by adding exception handling to Mercury.
But this isn't the only problem with destructive update. Semidet code
has the same problem:
:- pred mangle_array(array::mdi, array:muo) is semidet;
:- pred test(array::mdi) is semidet;
:- pred q(array::mdi, int::out) is det;
:- pred p(array::mdi, int::out) is det;
p(A, Z) :-
( mangle_array(A, A1),
test(A1) ->
q(A1, Z)
; q(A, Z)
).
(mdi and muo mean mostly destructive in and mostly unique out.) Unless I'm
missing something, this should be possible, and will require
trailing. But there's no nondet frame to tie the trail to! I don't
know how to handle this one, other than to force the compiler to
create an artificial choicepoint before the call to mangle_array/2,
and have the call to test/1 either backtrack into it or cut it away.
Is there an better alternative I don't see?
-Peter Schachte URL: http://www.cs.mu.oz.au/~pets/
pets at cs.mu.OZ.AU PGP: finger pets at 128.250.37.150 for key
Do insects spend hours demammaling their programs?
More information about the developers
mailing list