[mercury-users] Exceptions and unique modes

Peter Schachte schachte at cs.mu.OZ.AU
Thu Feb 22 16:18:20 AEDT 2001


On Wed, Feb 21, 2001 at 01:00:34PM +0100, Peter Ross wrote:
> This is why I am thinking that you need to use one name for the unique
> object and guarantee that in the presence of exceptions, this name will
> represent the last handle on the unique type.  I am hopeful that we
> can represent this as some sort of source-to-source transformation.

I think Peter's right.

If I understand correctly, the problem is that we need an operational
semantics that admits di/uo pairs being implemented either as a single data
structure which is destructively modified or as one which is copied.  Of
course, in the former case when an exception is raised, the data structure
has already been modified, so we can't get back the original value, and in
the latter case we'll naturally have the original value, and no easy access
to the latest value before the exception.

So we're looking for a model that will work in both cases.  I expect we're
agreed that we want the value after the exception to be the last value
before it, because making it be the original value would essentially render
the destructive update optimization useless.

One straightforward way to specify it is for any predicate with a di/uo mode
to notionally transform any throws it contains to parcel up the last value
of the di/uo thread(s) in the exception term it throws.  Similarly, it
should notionally wrap every goal in a catch wrapper that pastes the latest
value of the thread into the exception term and reraises the exception.  I
did say "notionally"; of course you wouldn't implement it that way.

The only catch I see is in matching the term hitchhiking along in the
exception term with the term coming out of the goal on success.  Eg, if p/2
has a di/uo mode,

	try(p(SomethingUnique), Result),
	(   Result = succeeded(NewUnique)
	;   Result = failed, think_of_something(NewUnique)
	;   Result = exception(Excpt),
	    how_do_i_find_it(Excpt, NewUnique)
	),
	...

Giving names to the threads could solve this problem.

-- 
Peter Schachte <schachte at cs.mu.OZ.AU>  You can tell the ideals of a nation
http://www.cs.mu.oz.au/~schachte/      by its advertisements.
Phone:  +61 3 8344 9166                    -- Norman Douglas 
Fax:    +61 3 9348 1184                
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list