[mercury-users] Indexing & operational semantics
Fergus Henderson
fjh at cs.mu.OZ.AU
Mon Feb 7 18:52:01 AEDT 2000
On 01-Feb-2000, Fergus Henderson <fjh at cs.mu.OZ.AU> wrote:
> On 31-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > I'm writing a term -> my_thing translator and I want to
> > raise an error if it sees a syntax error or attempt to
> > overload a primitive functor name. Some of the clauses
> > in the translator therefore look like this:
> >
> > translate(functor(atom("/\"), Args, Ctxt), Out) :-
> > require(list__length(Args) = 2, "/\ must have two args"),
> > Out = f(Args).
> >
> > Now it occurred to me that this could equally be written
> > as
> >
> > translate(functor(Name, Args, Ctxt), Out) :-
> > Name = atom("/\"),
> > require(list__length(Args) = 2, "/\ must have two args"),
> > Out = f(Args).
> >
> > which is something the compiler might very well do. In this
> > case, there's no dependency between the first and second lines
> > of the clause body, so there's a chance that they will be
> > reordered.
>
> Yes, the "strict commutative" semantics described in the
> language reference manual allows such reordering.
I should clarify that a bit.
The implementation should detect switches, and reordering of
conjunctions and disjunctions should only be allowed for those
conjunctions and disjunctions which remain after switch detection.
If translate/2 had mode
:- mode translate(in, out).
and there was another clause
translate(functor(Name, Args, Ctxt), Out) :-
Name = atom("something else"),
...
then the unification with "/\" would be part of a switch,
and so the compiler should in that case _not_ be allowed
to reorder the call to require/1 to occur before the
switch test.
That was, I believe, the original intent, but the reference
manual is not at all clear about this and it needs to be clarified.
--
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.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list