[m-users.] Question about multiple modes.

Matthias G├╝demann matthias at guedemann.org
Wed Aug 12 07:17:05 AEST 2015


Hi Jimi,

> The problem is writing the body. There is no way to tell within the
> body which mode we currently describe, to add the corresponding
> semantics. Ultimately, the compiler will create a separate C function
> for each mode, based on a single body that unambiguously describes ALL
> modes at once.  Am I correct?

not 100%, you can write different implementations for each mode,
e.g. you can have:

,----
| mult(A::in, B::out, C::in) :-
|   implementation1.
| 
| 
| mult(A::out, B::in, C::in) :-
|   implementation2.
| 
| mult(A::in, B::out, C::in) :-
|   implementation3.
`----

which each mode having a different implementation. In this case, mmc
will consider each mode as impure, as you treat different instatiations
of logic variables differently. This means you could implement the
meta-logic var/1 predicate using this.

Therefore you would have to declare all mult/3 predicates as equivalent
using the following pragma:

,----
| :- pragma promise_equivalent_clauses(mult/3).
`----

then the compiler trusts you that the decalarative semantics of all 3
different versions is the same (but of course it is up to you to ensure
this!).

There are probably other methods to approach this problem, but this
allows you to choose the most efficient implementation for each mode.

Matthias



More information about the users mailing list