Different code for different modes

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Jan 22 16:53:12 AEDT 1998


On 22-Jan-1998, Peter Schachte <pets at students.cs.mu.OZ.AU> wrote:
> Very occasionally, it is desirable or even necessary to have different code
> for different modes of a predicate.  Currently the only way to do that is to
> implement it as pragma c_code, which can then call back into Mercury if
> it must.  But this is rather inconvenient.  With the advent of impure
> predicates, it makes even more sense to have different code for different
> modes of a predicate implemented in Mercury.
> 
> I'd like to propose an extension to the Mercury language to allow different
> code for different modes of a predicate which seems pretty attractive to me.
> The syntax is largely due to Bart Demoen, and has been adopted as part of
> the HAL language.

How about the following alternative syntax?

	p(X::in, Y::out) :- p_1(X).
	p(X::out, Y::in) :- p_2(X).
	...

It would be an error to have both mode-specific and non-mode-specific
clauses for a single predicate.  It would be an error to specify the
modes for some but not all of the arguments.

I guess it would be reasonable to by default infer that such predicates
are `impure', and require an explicit `pragma promise_pure' if the
predicate was not declared `impure'.

This should be pretty easy to implement, because the clause_info
already has a list(proc_id) for each clause saying which mode(s)
it belongs to.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list