[mercury-users] Mercury needs a Tutorial
David Powers
powers at ist.flinders.edu.au
Mon Feb 15 15:16:22 AEDT 1999
Looks good - I'll keep comments/corrections brief.
In your program you have
:- import_module io.
In your explanation you have
:- use_module io.
The idea of programs having input/output parameters will be familiar to those
who learnt strict Jensen&Wirth Pascal (program asdf(input,output)).
Is "token" the appropriate word to describe "__" (something higher level
like operator perhaps)?
Rather than "some punctuation symbol" how about "something non-alphabetic"
(e.g. numbers start with digits).
"Think mathematically and you'll be fine!" is the last thing I would say to my
students... They'd run a mile...
Most examples came out centred (line by line), which looks a bit strange... I
guess this'll work out in the wash, or it may be exmh (I see you did centre
tables - the part before <p> was centred within the table, while the part
afterwards was indented as well as can be expected as I saw in the fibonacci
example).
Given that doing the factorial examples like this in Prolog would
return the sum of the appropriate number of 1's, do I assume that = acts like
Prolog's is and evaluates expressions. Moreoever the fibonacci example would
fail due to predicates not being evaluated and the non-existence of functions.
Interesting. It may be worth explicitly highlighting differences from Prolog
like this. The use of {...} needs to be spelled out a little more explicitly,
at least actually quoting the relevant line rather than expecting the reader to
look back, hunt for the braces (hard in my font) and figure what you are
talking about and why (--> adds to all predicates, not functions in both head
and tail and factorial doesn't do I/O and the definition doesn't have I/O
arguments. I'm a Prolog programmer and NL expert, and I had to make a little
effort to connect your {...} comment with the DCG shorthand and had skimmed
past them without noticing. (Unlike those who suggested that introducing DCG
notation in your first example was too much, I think it is appropriate to show
the simpler surface form.)
In teaching Prolog I strongly discourage use of ; (probably pretty common), and
also -> ; (less common). Possibly it is only the nesting of these I should
discourage, particularly as there are optimizations which are lost by doing so.
It may be worth commenting on this (to Prolog programmers) if there are special
reasons why these are used in Mercury where they would not be in Prolog.
So far so good...
Thanks for the effort, Looking forward to the next installment!
David
--
-- powers at acm.org http://www.cs.flinders.edu.au/People/David_Powers
Associate Professor David M. W. Powers PhD Facsimile: +61-8 820 13626
Director, AILab, Informatics & Engineering UniOffice: 08 820 13663
The Flinders University of South Australia Secretary: 820 12662
GPO Box 2100 ADELAIDE South Australia 5001 PrvMobile: +61-414-824307
More information about the users
mailing list