[mercury-users] Indexing & operational semantics

Peter Schachte schachte at cs.mu.OZ.AU
Tue Feb 1 12:28:50 AEDT 2000


On Tue, Feb 01, 2000 at 04:56:08AM +1100, Fergus Henderson wrote:
> On 31-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > translate(functor(Name, Args, Ctxt), Out) :-
> > 	Name = atom("/\"),
> > 	require(list__length(Args) = 2, "/\ must have two args"),
> > 	Out = f(Args).
> > 
> > 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.
> 
> > This would be a disaster, since I only want require/2
> > to be called provided Name = atom("/\").
> 
> In that case, you should either
> 	(1) use the "strict sequential" semantics,
> 	    which every Mercury implementation is required
> 	    to support (with the current Mercury
> 	    implementation, it is enabled by the
> 	    `--strict-sequential' option).
> or 
> 	(2) avoid writing such constructs,
> 	    instead using code like the code that you give
> 	    below.

Keeping conjunction commutative seems very desirable (let's not get
into EDCG issues here ;-), and the if-then-else form is rather bulky
and ugly, so it's really a shame to have to make this choice.  Maybe
it's time to put in an "and then" (sequential conjunction) operator?
Didn't Tom have one in his work on concurrency?  In any case, it seems
like a generally useful construct.  I expect Ralph would rather write
something like

	translate(functor(Name, Args, Ctxt), Out) :-
		Name = atom("/\") &&
		require(list__length(Args) = 2, "/\ must have two args"),
		Out = f(Args).

than

	translate(functor(Name, Args, Ctxt), Out) :-
		(   Name = atom("/\") ->
			require(list__length(Args) = 2, 
				"/\ must have two args")
		;
			fail
		),
		Out = f(Args).


I know I would.  (I'm using && as sequential conjunction for this
example.)  The only subtlety is in choosing the precedence for &&.
Should a, b && c, d associate as (a,b) && (c,d) or as a, (b && c), d?


-- 
Peter Schachte                     I know not with what weapons World War
mailto:schachte at cs.mu.OZ.AU        III will be fought, but World War IV will
http://www.cs.mu.oz.au/~schachte/  be fought with sticks and stones.
PGP: finger schachte at 128.250.37.3      -- Albert Einstein 
--------------------------------------------------------------------------
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