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

Mark Brown mark at mercurylang.org
Mon Jul 22 22:57:44 AEST 2019


Hi,

On Mon, Jul 22, 2019 at 8:36 PM Peter Wang <novalazy at gmail.com> wrote:
> > 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.
>
> You can see from the changelog that the keywords were already available
> very early on due to the NU-Prolog influence (NU-Prolog was used to
> bootstrap Mercury). As for why NU-Prolog had the keywords, someone will
> probably tell us.

NU-Prolog, also has the "non-logical" Prolog conditional, and the two
are different. From the NU-Prolog reference manual:

"Cond −> Goal1 ; Goal2
    (Non-logical).
    Operationally: similar to if Cond then Goal1 else Goal2 but (unlike
    if–then–else) there are no quantifiers, the call never delays and
Cond is never retried.
    If Cond succeeds then Goal1 is called; otherwise Goal 2 is called."

That is, it used the keywords for pure if-then-else to distinguish it
from the existing Prolog conditional, which it also implements.

Early on, the Mercury compiler could also be compiled by SICStus
Prolog, which *only* has the non-logical conditionals. So the compiler
writers would have originally had to use the "->;" form (and been
careful to use it safely).

But Mercury itself *only* has the pure form of conditional, hence
Mercury's "->;" is technically inconsistent with that of NU-Prolog and
other Prologs more generally. The "if-then-else" form is at least
consistent with NU-Prolog, and for that reason I think it is
preferred.

I would propose removing "-> ;" from the language but my flame proof
suit is at the drycleaners ;-)

Mark


More information about the users mailing list