[mercury-users] Native garbage collector for Mercury

Peter Schachte pets at cs.mu.OZ.AU
Mon Sep 14 16:44:22 AEST 1998


On Mon, Sep 14, 1998 at 04:15:10PM +1000, Thomas Charles CONWAY wrote:
> > 	count(Buffer, Len0, Len, IO0, IO) :-
> > 		(   is_empty(Buffer, IO0) ->
> > 			IO = IO0,
> > 			Len = Len0
> > 		;   next_char(Buffer, _Char, IO0, IO1),
> > 		    count(Buffer, Len0+1, Len, IO1, IO)
> > 		).
> 
> First your count code is illegal (since the final io__state from main
> must be `uo' not `muo'): the call to is_empty must be deterministic.

I don't see the problem.  is_empty is semidet and next_char is det, so
count is det.  Where's the backtracking?

> We can implement this in a variety of ways, but the most efficient is
> to use C to implement ref(T) as a pointer to a cell containing a pointer
> to the data (this data structure is sometimes known as a handle).
> However, if you insist on hobbling me so I can't use C

I do.

> you can use the
> user data field of the io__state to hold a map from ref(T)

of *which* io__state?  count, as I conceived it, takes an io__state as
input, and produces an io__state as output, and you aren't allowed to
change it between those points.  All parts of the io__state that are
needed to implement count *must* be there when you call count.
Otherwise you're cheating.

I was thinking of some scheme where you call

	generate_io_state(..., IO0, IO1) & count(...., IO1, IO2)

where the & means parallel conjunction, and an execution model that
allows count to proceed until it tries to read part of the io__state
that hasn't yet been written by generate_io_state.  Then you can model
(but not implement) the information flow from generate_io_state to
count as binding of shared variables.

-- 
Peter Schachte                | Apologists for Economic Darwinism seem to
mailto:pets at cs.mu.OZ.AU       | forget that the goal is maximum aggregate
http://www.cs.mu.oz.au/~pets/ | utility -- not just having the fittest
PGP: finger pets at 128.250.37.3 | corporations. -- me 



More information about the users mailing list