[mercury-users] Mercury needs a Tutorial

Bas de Bakker basde.bakker at pica.nl
Mon Feb 15 18:44:51 AEDT 1999


>>>>> "David" == David Powers <powers at ist.flinders.edu.au> writes:

A few selected replies...

    David> Given that doing the factorial examples like this in Prolog
    David> would return the sum of the appropriate number of 1's, do I
    David> assume that = acts like Prolog's is and evaluates
    David> expressions.

Not exactly, it's rather the other way around.  You can use 'is' in
Mercury, but it's just another spelling for '='.  Expressions are
always evaluated, e.g., you can write 'factorial(N1 - N2 + N3, F)'.

    David> It may be worth explicitly highlighting differences from
    David> Prolog like this.

Difficult point.  The tutorial isn't meant for Prolog programmers and
such comments may be distracting for those people who don't know
Prolog.

    David> In teaching Prolog I strongly discourage use of ; (probably
    David> pretty common), and also -> ; (less common).  Possibly it
    David> is only the nesting of these I should discourage,
    David> particularly as there are optimizations which are lost by
    David> doing so.

In Mercury, nested disjunctions are indexed just like top level
disjunctions and predicates with multiple clauses, so it makes no
difference for optimization.  You need to use if-then-else more often
than in Prolog to make sure the compiler knows a predicate does not
have multiple solutions.  See the transition guide for a better
explanation of this.

    David> It may be worth commenting on this (to Prolog programmers)
    David> if there are special reasons why these are used in Mercury
    David> where they would not be in Prolog.

See above, and the Prolog to Mercury transition guide as mentioned by
others.

Regards,
Bas.



More information about the users mailing list