Order of precedence

("Ian Bicking") bickiia at yang.earlham.edu
Fri Jan 29 00:10:17 UTC 1999


In message Wed, 27 Jan 1999 20:40:23 +0100,
  Joachim Durchholz <joachim.durchholz at munich.netsurf.de>  writes:
>Eliot & Linda Miranda wrote:
>> What are the relative recidences of + - * / \\ // < <= > >= = ~= ?
>
> From my above remarks, a highest-to-lowest precedence table is actually
> easy to construct, and actually observed in multi-precedence languages
> like C and Prolog:
>
> Exponentiation  ^ (is this actually in Smalltalk?)
> Multiplicative  * / // \\
> Relational      < <= > >=
> Equality        = == ~ ~~
> Assignment      :=

This is where I've always seen the benefit of the Smalltalk syntax.  If
there's precedence (besides, of course, left-to-right) then it wouldn't
really be fair to make precedence something magical about the base syntax
and inaccessable to user-created operators.  That the user/programmer is a
peer of the language designer/library creator is one of the most important
things about Smalltalk, IMHO.

But if everyone can play with precedence, the syntax gets out of hand.
If you aren't very familiar with all the operators used (and perhaps the
context as well, since they are just messages) it becomes difficult to read
code.  The precedence of a single operator could change the meaning of an
entire statement.  (I get the impression that this was a capability and
problem of Smalltalk 76...?)

So you have the Algols, which give power to the language designer, and
Lisps, which give up on infix entirely.

I like that Smallktalk figured out a way to do infix without tyranny.  I'm
just wondering or hoping that there might be some way that does everything
right without making compromises.  That's what rethinking is about --
everyone knows the compromises, languages have divided and families have
been formed around those compromises.  But maybe there's a different way of
thinking about it that lets you have it all.  IMHO, that's what Squeak (not
necessarily Smalltalk) is supposed to be about.

>> Or is maintaining readability less important than attempting to
>>   provide an inaccurate simulation of mathematical notation (e.g. *
>>   instead of adjacency)?
>
> Bah. No rethorics please. I understand you are accustomed to Smalltalk
> tradition and don't want to learn new tricks for little gain, but that
> doesn't necessarily mean that the position of anybody with a different
> opinion is so ridiculous as you present it here.

I must say I too was quite annoyed with the nit-picking that "*" is not the
same as adjacency.  Be it an x, a dot, or * doesn't matter -- that
confuses no one.  Changing the symbols is unimportant -- changing the
semantics *is* important.

>> I think very strongly that the current design of the infix rules is
>>   better than any other programming language I've used, that its easier
>>   to teach, that its easier to learn, and easier to use.

I'd like to point out that when I started this thread, I never meant that it
was too hard to learn Smalltalk's left-to-right rule.  Only that it could
confuse children who will later have to learn about the order of precedence.
Maybe the whole issue could be generalized and politicized: do we accept
outside conventions?  Is Squeak a world of its own?  If it is, is that being
high-minded or egotistic?  But those aren't really the questions I wanted to
ask... I was just hoping there was some way that I couldn't see that would
allow precedence without making Smalltalk into C.  Sigh.


                                              -- Ian Bicking





More information about the Squeak-dev mailing list