Re: Operator precedence

Liste des GroupesRevenir à cl awk 
Sujet : Re: Operator precedence
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.lang.awk
Date : 24. May 2024, 04:45:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240523203557.409@kylheku.com>
References : 1 2 3
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-05-23, Axel Reichert <mail@axel-reichert.de> 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! Prior to reading it I was kind of
indifferent (at least in infix programming languages, but not in typeset
mathematics).
>
I made it n-ary in TXR Lisp:
>
1> (expt 5 2)
25
2> (expt 5 2 3)
390625
>
... so conforming to the habit of typeset mathematics, which is based on
the fact that
>
    c
   b
  a
>
could be written as
>
   bc
  a
>
if meant to be left-associative. So having it right associative is the
more terse convention.

Yes. Also, in the left associative semantics, we have a choice. We can
do the exponentation earnestly as if by:

  (expt (expt 5 2) 3)

Or we can take advantage of the identity:

  (expt 5 (* 2 3))

The former could be important in some situation involving
floating-point: you can't always use simplifying identities.

The latter is favored when efficiency is more important.

A left associative n-ary expt function would have to make one of those
two choices: either doggedly do the exponentiations (such that the
function would be avoided by anyone looking for efficiency), or else
serve as a syntactic sugar for the exponent raised to the product
of the remaining arguments (which provides low value as a syntactic
sugar, and yet has to be avoided by someone who can't use that identity
for whatever reason).

I felt that the n-ary semantics of expt provided the best value
when right associative. It's not something obtainable by a ready
identity, and there is one obvious way to do it.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

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