[m-users.] if/then/else griping.
Mark Brown
mark at mercurylang.org
Mon Jul 22 17:26:05 AEST 2019
Hi,
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"
> ).
It's the parentheses that are vertically aligned, which I personally
prefer as it is the matching parenthesis that my editor highlights,
not the keyword.
> Maybe this is untrue, but my assumption for a while was that
> if/then/else was added to Mercury in the first place because people
> learning Mercury complained about formatting problems with the
> Prolog-style conditionals. This is odd as the new syntax retains any
> problem you'd have with the old syntax,
If one of your assumptions seems odd, perhaps that is telling you something? :-)
The semantics of Mercury's if-then-else is the same as NU-Prolog's
if-then-else (as opposed to the form written with "->" and ";"), which
is why I think the "if-then-else" spelling is preferred.
Mark
More information about the users
mailing list