[m-rev.] diff: allow memo tables to be reset

Ian MacLarty maclarty at cs.mu.OZ.AU
Mon Mar 7 17:33:15 AEDT 2005


Ralph Becket wrote:
> Zoltan Somogyi, Monday,  7 March 2005:
> 
>>On 07-Mar-2005, Ian MacLarty <maclarty at cs.mu.OZ.AU> wrote:
>>
>>>Would it be a good idea to have a version of memoing where the memo 
>>>tables only last for the duration of a call?
>>
>>Yes, it would. However, since such calls may be nested, it is not at all
>>obvious how one could implement it without adding distributed fat.
> 
> 
> How about converting
> 
> 	:- pragma memo_transient(p/n).
> 	p(...) :- ...
> 
> into something like
> 
> 	:- pragma foreign_code("C", "int p_depth = 0;")
> 	:- pragma foreign_proc("C", p_depth = (X::out),
> 		[will_not_call_mercury, promise_pure],

Should that promise_pure be there?

> 		"X = (MR_Word) &p_depth;"
> 	).
> 
> 	p(...) :-
> 		impure X = get_trailed_global(p_depth),
> 		impure set_trailed_global(p_depth, X + 1),
> 		...,
> 		impure set_trailed_global(p_depth, X),
> 		( if X = 0 then
> 			impure reset_p_table
> 		  else
> 		  	true
> 		).
> 
> where get_trailed_global, set_trailed_global, and reset_p_table do the
> obvious thing.
> 

I think you'd want to reset the tables for the predicates p calls, which 
are not necessarily always just p.

Maybe something like:

:- pragma memo_transient(p/n, [q1/m1, q2/m2, ..., qk/mk]).

Which says that the memo tables for q1, q2 etc. should be reset when a 
top level call to p/n finishes.  The programmer might only want certain 
memo tables to be reset (e.g. for predicates that are unlikely to be 
called with the same input for a different call to p).  The compiler 
might check that q1, q2 etc can be reached from p and give an error if 
they can't.

Ian.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list