[m-dev.] proposal for promise_pure scope warning

Peter Schachte schachte at csse.unimelb.edu.au
Wed Apr 16 10:54:40 AEST 2008


Ian MacLarty wrote:
> cached_computation(In, Out) :-
>     ( promise_pure (semipure lookup_value_in_cache(In, Cached)) ->
>         Out = Cached
>     ;
>         perform_computation(In, Out)
>     ).
> 
> It's incorrect because the goal
> 
>     lookup_value_in_cache(In, Cached)
> 
> is not pure.  It is not pure because you may get different results for
> the same input.  Only the body as a whole is pure, because only that
> goal always returns the same results for the same inputs.

Yes, you're right.  OK, I can't think of any realistic cases where a single 
call to a non-pure goals would be pure, so I don't object to the warning. 
But I do think you should document the recommended workaround for the unusual 
case where the promise *is* correct (and it shouldn't be to change the 
compiler options).  Maybe it should be to abstract out the call into a 
separate predicate that is promised pure, or to just promise_pure the whole 
predicate containing the call.

-- 
Peter Schachte              The spirit of resistance to government is so
schachte at cs.mu.OZ.AU        valuable on certain occasions that I wish it to
www.cs.mu.oz.au/~schachte/  be always kept alive.
Phone: +61 3 8344 1338          -- Thomas Jefferson
--------------------------------------------------------------------------
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