[mercury-users] Preferred coding style for switches

Ralph Becket rbeck at microsoft.com
Fri Dec 10 03:08:00 AEDT 1999


Say I was writing a predicate that basically implemented a decision table
comparing two arguments, the first having a type with constructors foo1 ..
fooM
and the second having a type with constructors bar1 .. barN.

Is there a preferred style for writing such a predicate, e.g.

p(foo1, bar1) :- ...
...
p(foo1, barN) :- ...
p(foo2, bar1) :- ...
...
...
p(fooM, barN) :- ...

over

p(foo1, X) :-
	(
		X = bar1,
		...
	;
		X = bar2,
		...
	;
	...
	;
		X = barN,
		...
	).
and so forth?

I've just rewritten several predicates from the first style (here N = M = 4
and not all `bar's need be considered for some `foo's) and, while there is
less verbiage on the screen thanks to the reduced number of clause heads,
I'm not convinced that it's any clearer - indeed, the latter style may be
worse.

Any opinions out there?

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