[m-users.] Idiomatic Mercury - if-then-else or (C->I;E)
Richard A. O'Keefe
ok at cs.otago.ac.nz
Mon Nov 23 11:52:56 AEDT 2015
On 20/11/2015, at 9:14 pm, Mark Brown <mark at mercurylang.org> wrote:
> Personally I find that if the condition extends over multiple lines,
> the (C->T;E) form is harder to follow because you can't tell it's a
> condition until you reach the end. That's particularly the case with
> long if-then-else chains: each goal occurring after one of the
> semicolons could either be a condition or the else clause, and the key
> to telling which may be many lines away.
If you write
( C1 ->
; C2 ->
it is pretty hard to mistake an if->then;else for
anything else. This is the style I have used and
recommended in Prolog for a long time. Another
alternative which might be better is
While both Prolog and Mercury let you write long
conditions, it isn't a good idea to do so, whatever
tokens you use for marking the syntax.
> Other reasons include that it looks like implication, which it's not,
No, it looks like a McCarthy M-expr conditional,
except for round parentheses instead of square brackets.
Implication, when used in Prolog, used => not -> .
Backus used this syntax in FP, see page number 620
> and that Mercury syntax already uses too many different kinds of
That's a good reason.
More information about the users