Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9754

Re: Operator precedence

From Kaz Kylheku <643-408-1753@kylheku.com>
Newsgroups comp.lang.awk
Subject Re: Operator precedence
Date 2024-05-24 03:45 +0000
Organization A noiseless patient Spider
Message-ID <20240523203557.409@kylheku.com> (permalink)
References <v2nium$1pl8f$1@dont-email.me> <20240523092856.646@kylheku.com> <87sey8movv.fsf@axel-reichert.de>

Show all headers | View raw


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

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-23 16:13 +0200
  Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-23 16:49 +0000
    Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-23 19:14 +0200
      Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-24 01:53 +0200
        Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-24 04:41 +0200
          Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-24 04:32 +0000
            Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-25 13:34 +0200
              Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-25 23:31 +0200
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-26 00:03 +0200
                Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-25 22:26 +0000
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-30 06:59 +0200
                Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-30 10:24 +0200
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-31 17:08 +0200
                Re: Operator precedence Christian Weisgerber <naddy@mips.inka.de> - 2024-05-26 00:37 +0000
                Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-26 02:06 +0000
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-30 07:26 +0200
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-30 07:06 +0200
                Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-30 10:22 +0200
                Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-31 17:16 +0200
            Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-25 23:31 +0200
              Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-26 01:29 +0000
        Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-30 10:17 +0200
          Re: Operator precedence Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2024-05-31 17:46 +0200
            Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-06-01 09:11 +0200
      Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-24 03:45 +0000
        Re: Operator precedence Axel Reichert <mail@axel-reichert.de> - 2024-05-25 13:09 +0200
          Re: Operator precedence Kaz Kylheku <643-408-1753@kylheku.com> - 2024-05-25 22:20 +0000

csiph-web