[m-users.] Idiomatic Mercury - if-then-else or (C->I;E)

Julien Fischer jfischer at opturion.com
Fri Nov 20 19:33:46 AEDT 2015


On Fri, 20 Nov 2015, Mark Brown wrote:

> Hi Matthias,
>
> On Fri, Nov 20, 2015 at 6:02 PM, Matthias Güdemann
> <matthias.guedemann at googlemail.com> wrote:
>> Hi,
>>
>> I just saw Julien's comment on Paul's example. There, and in other
>> commits I saw a preference of if-then-else over (C->I;E) to write
>> idiomatic Mercury.
>>
>> What are the reasons for this?
>
> 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.

Another reason is that if you get if-then-elses nested inside switches
or disjunctions (or vice versa) it can sometimes be difficult to work
out what a ';' belongs to, particularly if the code is badly formatted.

Julien.


More information about the users mailing list