Sujet : Re: Operator precedence
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.awkDate : 24. May 2024, 00:53:52
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2okuh$1vrvh$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 23.05.2024 19:14, Axel Reichert wrote:
Kaz Kylheku <643-408-1753@kylheku.com> writes:
Furthermore exponentation between on an intermediate precedence level
between unary minus and regular minus is simply insane.
This is a very good argument! [...]
I'd be interested why you think so. Unfortunately, and opposed to
the statement, I think there was no actual "argument" presented in
this quoted sentence.[*] - Please don't get me wrong; I'm really
interested in a relatable argument, and I also try to be unbiased!
If I understand Kaz' comment correctly, the ordering of the three
operators should be different? Are you saying that the order
unary minus
exponentiation
binary minus
is somehow "wrong"? - Yet, I don't see why.
Moreover, what seams reasonable (to me) is that _unary_ operators
should (typically/always?) bind tighter than _binary_ operators!
This would imply that exponentiation does not bind higher than the
unary minus. (And that the order of the upthread posted Shell and
Algol 68 expressions would thus fit better.)
Different languages also differ in their implementation choice as
shown; besides languages mentioned I read that (for example) Eiffel
implements it the way that GNU Awk has chosen. - That's now 2:2,
but counting majority is of course also no convincing argument.
OTOH, exponentiation is (typically/always?) right associative, so
it's may be somehow sensible to be handled differently compared to
the other [commutative] binary operators?
You see I'm still undecided, and still looking for explanations.
OTOH, given that this had been discussed by computer scientists
and mathematicians without clear answer, it may boil down to just
be an opinion to be decided in one way or the other.
It is interesting what the [German] Wikipedia[**] says about that.
Specifically that there's (besides exponentiation, multiplication/
division, addition/subtraction) additional categories in programming
languages; the [unary] sign that normally has a yet higher priority
than the exponentiation. - Well...
Janis
[*] "simply insane" doesn't contribute to a substantial argument.
Also the upthread mentioned "BEDMAS" sort of rule doesn't seem
to apply since unary operators are not mentioned (and there's a
difference between subtraction and negation). In our schools we
also learned such simplified rules, in our case it was "Punkt vor
Strich" (meaning multiplication and division comes before addition
and subtraction). And we had also the practice that exponentiation
has a tighter binding than a unary minus sign (as Kaz suggested).
[**]
https://de.wikipedia.org/wiki/Operatorrangfolge