[m-dev.] proposal for promise_pure scope warning

Peter Schachte schachte at csse.unimelb.edu.au
Tue Apr 15 18:06:12 AEST 2008


Ian MacLarty wrote:
> Do you mean something like the following:
> 
> cached_computation(In, Out) :-
>     ( semipure lookup_value_in_cache(In, Cached) ->
>         Out = Cached
>     ;
>         preform_computation(In, Out),
>         impure cache_result(In, Out)
>     ).
> 

Yup.

> Here the promise_pure must go around the whole body.  If you put the
> promise_pure around the calls to lookup_value_in_cache and cache_result,
> then the call to cache_result could get optimised away.

Ah, yes, you're right.  As long as the impure pred is det (or cc_multi) and 
has no outputs, which it usually would in the sort of example I was thinking of.

What about semipure goals?  They'll usually to have outputs and so couldn't 
be optimised away.  If you remove the impure goal from your example above 
(assuming some other code updated the cache at times), you'd be justified 
wrapping a promise_pure around the lookup goal alone, since the code does the 
right thing no matter in what order the lookup and update are executed.

-- 
Peter Schachte              It is the function of the citizen to keep the
schachte at cs.mu.OZ.AU        Government from falling into error.
www.cs.mu.oz.au/~schachte/      -- Robert H. Jackson
Phone: +61 3 8344 1338
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at csse.unimelb.edu.au
Administrative Queries: owner-mercury-developers at csse.unimelb.edu.au
Subscriptions:          mercury-developers-request at csse.unimelb.edu.au
--------------------------------------------------------------------------



More information about the developers mailing list