[mercury-users] Indexing & operational semantics
Ralph Becket
rbeck at microsoft.com
Tue Feb 1 03:51:07 AEDT 2000
I'm pretty sure the answer to this question is `yes', but
I just want to check.
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. This would be a disaster, since I only want require/2
to be called provided Name = atom("/\"). Since this is the
behaviour that I assume everybody expects, I infer that head
unifications work like this:
translate(functor(Name, Args, Ctxt), Out) :-
( if Name = atom("/\") then
require(list__length(Args) = 2, "/\ must have two args"),
Out = f(Args)
else
fail
).
with appropriate munging of output variables from the head
unification. I just couldn't find anything about this in the
reference manual.
Ralph
--------------------------------------------------------------------------
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