[m-users.] if/then/else griping.

M McDonough foolkingcrown at gmail.com
Tue Jul 23 05:37:22 AEST 2019


 On Mon, Jul 22, 2019 at 4:16 PM Julian Fondren <jfondren at minimaltype.com>
wrote:
>    % Mercury stdlib seems to have settled on this style.
>    % the initial 'if' looks unbalanced vs. the rest of the code.
>    daytype(D) = R :-
>        ( if D = wednesday then
>            R = "humpday"
>        else if (D = sunday; D = saturday) then
>            R = "weekend"
>        else
>            R = "workday"
>        ).

The usual way I write it is:

( if
    D = wednesday
then
    R = "humpday"
else if
    (D = sunday; D = saturday)
then
    R = "weekend"
else
    R = "workday"
)

This keeps the arms mostly balanced, although it does take more
vertical space. Although I also really think that using full
disjunctions is really usually preferable to if/then/else, and for this
example I would probably have just written a series of rules each
unifying a single weekday value.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20190722/c99c81ce/attachment.html>


More information about the users mailing list