[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 ->
T1
; C2 ->
T2
;
F
)
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
( C1
-> T1
; C2
-> T2
; F
)
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
in https://www.cs.cmu.edu/~crary/819-f09/Backus78.pdf
> and that Mercury syntax already uses too many different kinds of
> arrows.
That's a good reason.
More information about the users
mailing list