[mercury-users] Exceptions and unique modes

Peter Schachte schachte at cs.mu.OZ.AU
Thu Feb 22 22:44:31 AEDT 2001


On Thu, Feb 22, 2001 at 05:01:28PM +1100, Fergus Henderson wrote:
> On 22-Feb-2001, Peter Schachte <schachte at cs.mu.OZ.AU> wrote:
> > 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.
> 
> So how would you implement it?

Have you ever heard how Albert Einstein explained radio?

Imagine you have some kind of map that maps from names to the corresponding
unique values, and assume all the unique values are stored in this one map.
Call it an IO state, if you like.  We know how to handle this case, right?
When you pull the tail in the throw/1 goal, you hear the meow in the
try_io/4, right?  This is much like the unique store solution you just
posted, except that it uses a map because I want my code to assign a name to
the unique thing.

My proposal is just like that, only there's no map.

That is, I'm suggesting we use dynamically scoped hidden variables, aka
"global variables."  They solve the problem because the variable name gives
continuity to the unique value.  To answer your question, a term won't be
deallocated until the variable holding it is reassigned, at which point we
don't mind what happens to it, exception or not.

One thing I've just realized I'm not sure how to handle, though, is the
scoping, and that's pretty important.  If we have a unique list being
handled recursively, inside the recursion we'll keep assigning each tail of
the list to a nested scope of the same variable name.  We certainly don't
want an exception happening deep in the recursion to propagate up to the top
of the recursion with this variable bound to some inner tail of the list!

I should also confess that my argument-threading implementation of global
variables wouldn't handle this very easily.  You really want an
implementation that places each global variable in a fixed memory address.

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