Re: Operator precedence

Liste des GroupesRevenir à cl awk 
Sujet : Re: Operator precedence
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.awk
Date : 24. May 2024, 03:41:11
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v2ouo9$2547f$1@dont-email.me>
References : 1 2 3 4
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
After pondering a bit more I think this is my personal resume...

On 24.05.2024 01:53, Janis Papanagnou wrote:
[...]
Moreover, what seams reasonable (to me) is that _unary_ operators
should (typically/always?) bind tighter than _binary_ operators!

An example may make things probably more apparent; in the expression

    5 * -3 ^ 2

it would never occur to me to not consider the "-3" as an entity.
Because of the typical inherently tight coupling of unary operators.

(Assuming an interpretation of

    5 * -(3 ^ 2)

would look just wrong to me.)

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.)

BTW, Unix 'bc' also behaves that way

  $ bc -l <<< " 5 * -3 ^ 2 "
  45


<off-topic>
Let me add an Algol 68 anecdote (sort of)... You can of course adjust
the operator precedences in that language to fit your preferences.
And since you have more than one representation for the exponentiation
in Algol 68 - in the Genie compiler for example '^', 'UP', and '**' -
you can even change just one of them (if you like), for example

  BEGIN
PRIO UP = 5;
INT a=5;
print ((a ^ 2, - a ^ 2, 0 - a ^ 2, newline));
print ((a UP 2, -a UP 2, 0-a UP 2, newline));
print ((a ** 2, -a ** 2, 0-a ** 2, newline));
SKIP
  END

produces
        +25        +25        -25
        +25        +25        +25
        +25        +25        -25

Scary! :-)

Janis


Date Sujet#  Auteur
23 May 24 * Operator precedence27Janis Papanagnou
23 May 24 `* Re: Operator precedence26Kaz Kylheku
23 May 24  `* Re: Operator precedence25Axel Reichert
24 May 24   +* Re: Operator precedence21Janis Papanagnou
24 May 24   i+* Re: Operator precedence17Janis Papanagnou
24 May 24   ii`* Re: Operator precedence16Kaz Kylheku
25 May 24   ii +* Re: Operator precedence13Axel Reichert
25 May 24   ii i`* Re: Operator precedence12Janis Papanagnou
26 May 24   ii i `* Re: Operator precedence11Janis Papanagnou
26 May 24   ii i  +* Re: Operator precedence4Kaz Kylheku
30 May 24   ii i  i`* Re: Operator precedence3Janis Papanagnou
30 May 24   ii i  i `* Re: Operator precedence2Axel Reichert
31 May 24   ii i  i  `- Re: Operator precedence1Janis Papanagnou
26 May 24   ii i  +* Re: Operator precedence4Christian Weisgerber
26 May 24   ii i  i+* Re: Operator precedence2Kaz Kylheku
30 May 24   ii i  ii`- Re: Operator precedence1Janis Papanagnou
30 May 24   ii i  i`- Re: Operator precedence1Janis Papanagnou
30 May 24   ii i  `* Re: Operator precedence2Axel Reichert
31 May 24   ii i   `- Re: Operator precedence1Janis Papanagnou
25 May 24   ii `* Re: Operator precedence2Janis Papanagnou
26 May 24   ii  `- Re: Operator precedence1Kaz Kylheku
30 May 24   i`* Re: Operator precedence3Axel Reichert
31 May 24   i `* Re: Operator precedence2Janis Papanagnou
1 Jun 24   i  `- Re: Operator precedence1Axel Reichert
24 May 24   `* Re: Operator precedence3Kaz Kylheku
25 May 24    `* Re: Operator precedence2Axel Reichert
26 May 24     `- Re: Operator precedence1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal