[mercury-users] mercury website (was Suggestion: new operator)
Richard A. O'Keefe
ok at atlas.otago.ac.nz
Thu Oct 26 08:31:57 AEDT 2000
"Mattias Waldau" <mattias.waldau at abc.se> wrote:
The main point I am trying to make is that Mercury has followed the normal
Prolog-tradition and kept Prolog bad syntax. The reason Prolog has this
syntax, is that it is easy to implement parser in Prolog for Prolog's kind
of syntax. That decision was made more than 20 years ago.
This is a fantasy. It is easy to implement parsers in Prolog, full stop.
If someone wants a different syntax for Prolog, it is easy enough to do.
In fact I've done it a couple of times myself. Most painfully obviously,
consider the fact that Edinburgh Prolog syntax is *different* from
Marseilles Prolog syntax. Prolog has the excellent syntax it has because
that is a nice syntax to have. (As another obvious data point: the
parser in C Prolog is written in C, not Prolog.)
I do not understand why we have to continue this tradition, and
still make it worse by using '^' where every other normal program
language would use '->' or '.',
COBOL:
field OF record
field IN record
Algol 68:
field OF record
If we are to use an operator for fields, my preference would certainly
be for "field of Record".
Fortran:
record % field
PL/I, C, C++:
record . field
pointer -> field
Pascal: Ada:
Record . Field Record . Field
Pointer ^. Field Pointer . Field
Or Pointer . all . Field
Erlang:
record # field
Lisp:
(field record)
A common pseudo-code tradition (also in some assemblers):
field(pointer)
For what it's worth, the Clean equivalent of "R ^ f := E" is {R & f = E}.
I suppose "normal program language" means "looks like C or Pascal".
Whatever one thinks of "^" (and I for one really don't care for it)
it is rather less odd than Fortran's choice.
using '@' where other languages use '[' or '(', and so on.
Here we go again.
Fortran, COBOL:
A(I) Most 6-bit character sets didn't include []
Algol 60
A[I[ or literally subscript: A
Algol 68, C, Pascal: I
A[I] only
BCPL:
A!I or I!A (which is why i[a] is the same as a[i] in C to this day)
Scheme: Lisp:
(vector-ref A I) (aref A I)
Haskell:
a!i
ML:
{Word8,Char,WideChar,Bool,Int,Int#,Real,Real#,}Vector.sub(v,i)
{Word8,Char,WideChar,Bool,Int,Int#,Real,Real#,}Array.sub(a,i)
{Word8,Char,WideChar,Bool,Int,Int#,Real,Real#,}Array.update(a,i,x)
e.g. Int16Vector.sub(vector_of_16_bit_ints, index)
OCaml (has probably the best strict fp compiler around):
a.(i) yes, a dot _and_ parens
Smalltalk:
a at: i
Eiffel:
a at i a.item(i) a.entry(i)
(entry is redefinable, item is frozen)
Once again, we find that "normal program language" means "looks like C
or Pascal", because once we open our eyes to a wider world we find no
consensus at all. The use of an infix operator is in fact quite common
(note that the designers of J regarded the use of [] as a major wart in
APL and replaced that by operators).
Mercury's main feature - like backtracking and unification (?) -
must of course be understood by the programmer, but I doen't see
why these feature must affect all of the syntax of the language.
But of course they don't. The syntax must be compatible with the type
system, that is, it must carve formulas up into pieces in suitable ways.
That's fairly easy to accomplish. But there is no need for us to copy
quirks and oddities of the past simply because C and Pascal do things
that way. You never know, something different must just be better.
Might it be so that Mercury needs this syntax in order to be a
logic programming language? Otherwise people would just say
that it is an ML-type of language with builtin searching?
Presumably this is meant as a rather unfunny joke, because no-one
familiar with logic programming languages could take it seriously.
Marseilles Prolog syntax was different, micro-Prolog syntax was
different, Prolog-III syntax was different, LM-Prolog syntax was
different, LogLisp syntax was different, Trilogy syntax was different,
and no two of those agreed either.
Lists being rather more important to logic and to functional languages
than array subscripting, Mercury has something better to do with [] than
to waste them on array subscripts, and so does ML, which uses [] for
lists and sub() for subscripts. As for dot, modules are extremely
important in ML, and (thanks to its almost nonexistent support for
overloading) referred to extremely frequently, So . is used for module
prefixes in ML. -> is used in all typed functional languages that I know
of to express function types, and the use of "->" to express "if" actually
predates all current programming languages except COBOL and Fortran.
We must always be on our guard against "C envy". C has a great many
merits, but good syntax design is most assuredly not one of them.
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list