Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

NOWPRINT. NOWPRINT. Clemclone, back to the shadows again. -- The Firesign Theater


devel / comp.lang.misc / Re: Order of transformation of values

SubjectAuthor
* Order of transformation of valuesJames Harris
+* Re: Order of transformation of valuesDmitry A. Kazakov
|`* Re: Order of transformation of valuesJames Harris
| `* Re: Order of transformation of valuesDmitry A. Kazakov
|  +* Re: Order of transformation of valuesBart
|  |`* Re: Order of transformation of valuesDmitry A. Kazakov
|  | `* Re: Order of transformation of valuesJames Harris
|  |  `* Re: Order of transformation of valuesDmitry A. Kazakov
|  |   `* Re: Order of transformation of valuesJames Harris
|  |    `* Re: Order of transformation of valuesDmitry A. Kazakov
|  |     `* Re: Order of transformation of valuesJames Harris
|  |      `- Re: Order of transformation of valuesJames Harris
|  `* Re: Order of transformation of valuesJames Harris
|   `* Re: Order of transformation of valuesDmitry A. Kazakov
|    +* Re: Order of transformation of valuesJames Harris
|    |`* Re: Order of transformation of valuesDmitry A. Kazakov
|    | `- Re: Order of transformation of valuesJames Harris
|    `* Re: Order of transformation of valuesJames Harris
|     `- Re: Order of transformation of valuesJames Harris
+* Re: Order of transformation of valuesBart
|`- Re: Order of transformation of valuesJames Harris
`* Re: Order of transformation of valuesAlexei A. Frounze
 `* Re: Order of transformation of valuesBart
  `* Re: Order of transformation of valuesAlexei A. Frounze
   `- Re: Order of transformation of valuesBart

1
Order of transformation of values

<smb189$qs8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1176&group=comp.lang.misc#1176

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Order of transformation of values
Date: Mon, 8 Nov 2021 11:21:45 +0000
Organization: A noiseless patient Spider
Lines: 118
Message-ID: <smb189$qs8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 Nov 2021 11:21:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ef109d65fb590c5ee86153aca0071591";
logging-data="27528"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19fSQMIcFr/4t1uxot9o5K2jyZV5eUUMtI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:Yoy/Q1OS1Z2PR+9q5v7xSNV1i1c=
Content-Language: en-GB
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: James Harris - Mon, 8 Nov 2021 11:21 UTC

Here's a postulation which doesn't need a reply but you might find it
interesting.

I /suggest/ that in expressions as used in programming languages there
is a natural sequence in which values are transformed by the operators -
and that most languages don't follow it!

The sequence is:

1. Addresses
2. Bit patterns
3. Numbers
4. Booleans

As mentioned in a recent thread the operators which work with addresses
have to be applied first. That's because while addresses can always be
dereferenced to obtain what's at those addresses it's not meaningful to
go from a value to where it is stored. (The value produced so far is, in
fact, often in a register or on the top of the stack; either way, its
location is meaningless.)

The controversial part of the above is where I've put bit patterns so
let me come back to those below.

Going to the other end of the list first, the boolean operators (AND,
OR, NOT etc) don't just consume but also produce booleans. Thus once one
gets to boolean values the natural choice for how to combine them will
only produce more booleans. Therefore booleans are at the end.

Working upwards, boolean values are typically produced by comparisons.
The equality comparisons (== and !=) will work with anything; however
the relative comparisons (<, <=, >=, >) don't make much sense on bit
patterns but they do apply well to numbers. That's why I've put numbers
immediately above booleans.

That results, so far, in

* Addresses (manipulated by array lookup, field selection etc)
* Numbers (compared with <, etc; manipulated by +, etc)
* Booleans (manipulated by AND, OR, etc)

Where, though do bit patterns (as processed by bitwise operators) fit in?

One could make a case for simply not allowing bit patterns to be
combined with numbers. For example,

a + b & c

would be prohibited for having + and & adjacent to each other, there
being no precedence between them.

There would then be two separate streams of transformation:

addresses --> numbers --> booleans
addresses --> bit patterns --> booleans

IOW numbers and bit patterns could be read from store and compared to
produce booleans but numbers and bit patterns could not directly be
combined with each other (except in shifts where the RH operand is a
number).

A second option is to blur the distinction between bit patterns and
numbers and to intermix operations. (The C approach?)

A third is to insert bit patterns between numbers and booleans:

addresses --> numbers --> bit patterns --> booleans

but it makes little sense to go from numbers (for which all comparisons
are meaningful) to bit patterns (for which only some comparisons are
meaningful) and then to apply comparison operators to them.

A fourth and final option is

addresses --> bit patterns --> numbers --> booleans

In that, the values read from addresses would be regarded initially as
bit patterns. Then, once the bit patterns have been manipulated (if at
all) the results would be treated as numbers. Then the numbers could be
subject to the full range of comparison operations and booleans would be
produced.

ATM I follow the latter (fourth) approach. My operators are therefore in
order (high to low)

1. Address manipulations (as in the other recent thread)
2. Bit-pattern manipulation (&, !, etc)
3. Arithmetic manipulation (+, *, etc)
4. Comparisons (<, !=, etc)
5. Logical manipulation (AND, NOT, etc)

As an example, in

if A * B & Mask > C

the bitwise operator would be evaluated first resulting in

if A * (B & Mask) > C

then the arithmetic operator to give

if (A * (B & Mask)) > C

I should say that there are precedences within each group. In the
Arithmetic group * is applied before +, for example. But the groups are
applied in the order stated; all bit-pattern operators are applied
before any arithmetic operators, for instance.

As a side benefit, AISI having the operators in groups makes it easier
for a programmer to remember the precedences.

As I say, no need to reply. The above is just my rationale for ordering
precedences as I have them.

--
James Harris

Re: Order of transformation of values

<smb57g$1qi6$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1178&group=comp.lang.misc#1178

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!Hx95GBhnJb0Xc8StPhH8AA.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 13:29:36 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smb57g$1qi6$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="59974"; posting-host="Hx95GBhnJb0Xc8StPhH8AA.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Mon, 8 Nov 2021 12:29 UTC

On 2021-11-08 12:21, James Harris wrote:

> ATM I follow the latter (fourth) approach. My operators are therefore in
> order (high to low)
>
>   1. Address manipulations (as in the other recent thread)
>   2. Bit-pattern manipulation (&, !, etc)
>   3. Arithmetic manipulation (+, *, etc)
>   4. Comparisons (<, !=, etc)
>   5. Logical manipulation (AND, NOT, etc)

Makes little to no sense.

The precedence rules usually distinguish unary and dyadic operators,
because that is what the reader expects.

The unary operators almost always have a higher precedence. Which is why
your rules make no sense in the first place:

A + not B

is never

not (A + B)

and

A * -B

is never

- (A * B)

And

- not A

is never

not (-A)

should "not" really had lower precedence than "-".

"not" and "-" have same precedence.

[Mixing prefix and suffix unary operators is fun!]

The exception from the rule are dyadic meta-operators like member
extraction etc. They have the highest precedence (and are "meta" because
some operands are not expressions, normally).

not A.B

means

not (A.B)

While

A.not B

is illegal, because here "not B" is an expression.

Then "+" and "*" never have same precedence in any sane language.

The natural precedence used by sane languages:

1. Namespace, member extraction A.B[C] means "[]"("."(A,B),C)
2. Indexing
3. Unary operators, prefix are right-to-left, suffix are left-to-right
4. Dyadic operators
4.1. Exponentiation (**)
4.2. Multiplicative (*, /)
4.3. Additive (+, -)
4.4. Comparisons (<, >, =)
4.5. Lattice (and, or, xor)

4.1 would conflict with 3 for most readers with background in mathematics:

-A**B

So 4.1 is almost like 3.

If you wanted assignment operator, it should have asymmetric precedence:

A + B := C + D

is expected to be

A + (B := (C + D))

Same is true for exponentiation operator. Most people would read

A**B**C

as

A**(B**C)

Splitting lattice operations into logical and bit-wise is controversial.
You would need two sets of and/or/not operators.

If you want to mix "and" with "or" as C allows for && and ||, then "and"
is an equivalent of "*" and "or" is of "+". Compare:

x * 0 = 0 x and 0 = 0
x + 0 = x x or 0 = x

So you could put bit-wise "and" into multiplicative and "or" into
additive operators. But as I said it is rather controversial. I would
just forbid mixing arithmetic and lattice operators.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smbac6$3st$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1180&group=comp.lang.misc#1180

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 13:57:29 +0000
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <smbac6$3st$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 8 Nov 2021 13:57:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5aecade92803dad329ae52332fcb0c0e";
logging-data="3997"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18zmPailinTLeIEnWsFMuQdDYnSdHvP7Bc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Cancel-Lock: sha1:GqKP8Hz/dHAZu0SG3DO33xdJLPs=
In-Reply-To: <smb189$qs8$1@dont-email.me>
 by: Bart - Mon, 8 Nov 2021 13:57 UTC

On 08/11/2021 11:21, James Harris wrote:
> Here's a postulation which doesn't need a reply but you might find it
> interesting.
>
> I /suggest/ that in expressions as used in programming languages there
> is a natural sequence in which values are transformed by the operators -
> and that most languages don't follow it!
>
> The sequence is:
>
>   1. Addresses
>   2. Bit patterns
>   3. Numbers
>   4. Boolean
....

> As I say, no need to reply. The above is just my rationale for ordering
> precedences as I have them.

You're precedences should depend on type?

A few problems there:

* When parsing code, you might not know the types of things until later.
This makes it harder to create the right shape of AST

* In dynamic languages, you probably won't know the types of things
until runtime. And then, the types for the /same/ expression may be
different each time it's executed

* Operators may also be applied between types not in your list, and
arbitrary user-types.

So I think that type should not play a part in this.

Re: Order of transformation of values

<smbbih$dj0$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1182&group=comp.lang.misc#1182

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 14:17:52 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <smbbih$dj0$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smbac6$3st$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 8 Nov 2021 14:17:53 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ef109d65fb590c5ee86153aca0071591";
logging-data="13920"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/AFhUOrZ0Z0RZmBB/6sudLlTw1vf3I/DE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:4JW2n4v1dPYX92b5Zr4H3qTyXlw=
In-Reply-To: <smbac6$3st$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Mon, 8 Nov 2021 14:17 UTC

On 08/11/2021 13:57, Bart wrote:
> On 08/11/2021 11:21, James Harris wrote:
>> Here's a postulation which doesn't need a reply but you might find it
>> interesting.
>>
>> I /suggest/ that in expressions as used in programming languages there
>> is a natural sequence in which values are transformed by the operators
>> - and that most languages don't follow it!
>>
>> The sequence is:
>>
>>    1. Addresses
>>    2. Bit patterns
>>    3. Numbers
>>    4. Boolean
> ...
>
>> As I say, no need to reply. The above is just my rationale for
>> ordering precedences as I have them.
>
> You're precedences should depend on type?

No! That would be a nightmare - as you go on to suggest (now snipped).

Imagine that all the identifiers in the following have been declared as
uint 64, except E which is a record but E.F is a field which is also
uint 64.

A and B > C + D & E.F

That shows one operator from each group but they still work on uint 64s.

....

--
James Harris

Re: Order of transformation of values

<smbgc6$kh7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1185&group=comp.lang.misc#1185

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 15:39:49 +0000
Organization: A noiseless patient Spider
Lines: 207
Message-ID: <smbgc6$kh7$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 8 Nov 2021 15:39:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ef109d65fb590c5ee86153aca0071591";
logging-data="21031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+oJxNJlG1Y6G3peJAHoMsbks2RRRGB9qs="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:3h7x171k1/4Oi7uMW1tNu0tjHY0=
In-Reply-To: <smb57g$1qi6$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Mon, 8 Nov 2021 15:39 UTC

On 08/11/2021 12:29, Dmitry A. Kazakov wrote:
> On 2021-11-08 12:21, James Harris wrote:
>
>> ATM I follow the latter (fourth) approach. My operators are therefore
>> in order (high to low)
>>
>>    1. Address manipulations (as in the other recent thread)
>>    2. Bit-pattern manipulation (&, !, etc)
>>    3. Arithmetic manipulation (+, *, etc)
>>    4. Comparisons (<, !=, etc)
>>    5. Logical manipulation (AND, NOT, etc)
>
> Makes little to no sense.

I'm glad you think so.

;-)

>
> The precedence rules usually distinguish unary and dyadic operators,
> because that is what the reader expects.
>
> The unary operators almost always have a higher precedence.

"Almost always"?!

>
> Which is why
> your rules make no sense in the first place:
>
>    A + not B
>
> is never
>
>    not (A + B)
>
> and
>
>    A * -B
>
> is never
>
>    - (A * B)
>
> And
>
>    - not A
>
> is never
>
>    not (-A)

Those are strange examples. You say they'd never match but I wouldn't
expect them to.

>
> should "not" really had lower precedence than "-".

Well, think of

not A > B
not A <= - F()

>
> "not" and "-" have same precedence.
>
> [Mixing prefix and suffix unary operators is fun!]

It can be. :-(

>
> The exception from the rule are dyadic meta-operators like member
> extraction etc. They have the highest precedence (and are "meta" because
> some operands are not expressions, normally).

Exceptions to rules and special 'meta' forms? Has your account been
hijacked, Dmitry? I remember you calling Bart's parsing a "mess" for
similar.

>
>    not A.B
>
> means
>
>    not (A.B)
>
> While
>
>    A.not B
>
> is illegal, because here "not B" is an expression.
>
> Then "+" and "*" never have same precedence in any sane language.
>
> The natural precedence used by sane languages:
>
> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
> 2. Indexing

Why split namespace and indexing when the operations can be mixed
freely? E.g.

X[i].field.subfield[j].datum

> 3. Unary operators, prefix are right-to-left, suffix are left-to-right

Are you saying you would put logical NOT in there because it's unary?

> 4. Dyadic operators
>   4.1. Exponentiation (**)
>   4.2. Multiplicative (*, /)
>   4.3. Additive (+, -)
>   4.4. Comparisons (<, >, =)
>   4.5. Lattice (and, or, xor)

Most of those are standard. I have

^ exponentiation
+- monadic plus and minus
*/ times, divide, remainder etc
+- dyadic plus and minus
... all the comparison operators with one precedence
... all the boolean operators with their own precedences

>
> 4.1 would conflict with 3 for most readers with background in mathematics:
>
>    -A**B

I would parse that 'correctly' as

- (A ^ B)

(using ^ for exponentiation) because ^ has higher precedence than prefix
unary minus. Your mathematicians should be happy. :-)

>
> So 4.1 is almost like 3.
>
> If you wanted assignment operator, it should have asymmetric precedence:
>
>    A + B := C + D
>
> is expected to be
>
>    A + (B := (C + D))
>
> Same is true for exponentiation operator. Most people would read
>
>    A**B**C
>
> as
>
>    A**(B**C)

That's how I would parse it - right to left. I think that exponentiation
is the only operator in my entire table which is right-to-left.

>
> Splitting lattice operations into logical and bit-wise is controversial.
> You would need two sets of and/or/not operators.

That's no problem. I use symbols for bitwise and words for booleans. For
consistency they both follow the same order: not, and, xor, or.

In order of application they would be:

Bitwise:
<< >> shifts
! bitnot
& bitand
% bitxor
# bitor

Then, later:

Boolean
not logical not
and logical and (shortcutting)
xor logical xor
or logical or (shortcutting)

>
> If you want to mix "and" with "or" as C allows for && and ||, then "and"
> is an equivalent of "*" and "or" is of "+". Compare:
>
>    x * 0 = 0    x and 0 = 0
>    x + 0 = x    x or  0 = x
>
> So you could put bit-wise "and" into multiplicative and "or" into
> additive operators.

Sounds as though you and Bart are on the same page on taking a
structural approach to precedences rather than a semantic one.

> But as I said it is rather controversial. I would
> just forbid mixing arithmetic and lattice operators.
>

Fine. Though what would a programmer do if he had a genuine need to
'mix' them?

--
James Harris

Re: Order of transformation of values

<smbjo6$17a2$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1186&group=comp.lang.misc#1186

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 17:37:27 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smbjo6$17a2$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="40258"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Mon, 8 Nov 2021 16:37 UTC

On 2021-11-08 16:39, James Harris wrote:
> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:
>> On 2021-11-08 12:21, James Harris wrote:
>>
>>> ATM I follow the latter (fourth) approach. My operators are therefore
>>> in order (high to low)
>>>
>>>    1. Address manipulations (as in the other recent thread)
>>>    2. Bit-pattern manipulation (&, !, etc)
>>>    3. Arithmetic manipulation (+, *, etc)
>>>    4. Comparisons (<, !=, etc)
>>>    5. Logical manipulation (AND, NOT, etc)
>>
>> Makes little to no sense.
>
> I'm glad you think so.
>
> ;-)

I am too! (:-))

>> The precedence rules usually distinguish unary and dyadic operators,
>> because that is what the reader expects.
>>
>> The unary operators almost always have a higher precedence.
>
> "Almost always"?!

Yes, with some exceptions.

>> Which is why your rules make no sense in the first place:
>>
>>     A + not B
>>
>> is never
>>
>>     not (A + B)
>>
>> and
>>
>>     A * -B
>>
>> is never
>>
>>     - (A * B)
>>
>> And
>>
>>     - not A
>>
>> is never
>>
>>     not (-A)
>
> Those are strange examples. You say they'd never match but I wouldn't
> expect them to.

These are examples why unary operation should have higher precedence.

>> should "not" really had lower precedence than "-".
>
> Well, think of
>
>   not A > B
>   not A <= - F()

Even when not is bit-wise?

not A + B * C + D

And you have the problem of mixing unary operators having different
precedence:

- not A

E.g. in

- not A + B * C + D

It is inconsistent.

>> The exception from the rule are dyadic meta-operators like member
>> extraction etc. They have the highest precedence (and are "meta"
>> because some operands are not expressions, normally).
>
> Exceptions to rules and special 'meta' forms? Has your account been
> hijacked, Dmitry? I remember you calling Bart's parsing a "mess" for
> similar.

Not similar, purely mathematically, it is sort of recursion into what
you treat as an expression to resolve. It must stop at some point. In
most languages it stops in the second argument of A.B. If you want a
dynamic member resolution you would use A."B" but still keep the rules same.

>> The natural precedence used by sane languages:
>>
>> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
>> 2. Indexing
>
> Why split namespace and indexing when the operations can be mixed
> freely? E.g.
>
>   X[i].field.subfield[j].datum

Compare:

field.subfield[j] ---> (field.subfield)[j]

with

field+subfield[j] ---> field + (subfield[j])

>> 3. Unary operators, prefix are right-to-left, suffix are left-to-right
>
> Are you saying you would put logical NOT in there because it's unary?

Right, see above.

>> 4. Dyadic operators
>>    4.1. Exponentiation (**)
>>    4.2. Multiplicative (*, /)
>>    4.3. Additive (+, -)
>>    4.4. Comparisons (<, >, =)
>>    4.5. Lattice (and, or, xor)
>
> Most of those are standard. I have
>
>   ^    exponentiation
>   +-   monadic plus and minus
>   */   times, divide, remainder etc
>   +-   dyadic plus and minus
>   ...  all the comparison operators with one precedence
>   ...  all the boolean operators with their own precedences
>
>>
>> 4.1 would conflict with 3 for most readers with background in
>> mathematics:
>>
>>     -A**B
>
> I would parse that 'correctly' as
>
>   - (A ^ B)

To me it is not obvious, why not

(-A) ^ B?

And the counter example is this:

A ^ -B

If ^ preceded -, then that should too become

-(A ^ B)

My choice would be allow

A ^ -B ---> A ^ (-B)
-A ^ B ---> Syntax error, give me parenthesis.

So, unary always precedes dyadic, except the metas.

> (using ^ for exponentiation) because ^ has higher precedence than prefix
> unary minus. Your mathematicians should be happy. :-)

Traditionally in mathematics circumflex (hat) means something like
"vector". Using it for exponentiation was one of so many C's blunders.

>> So 4.1 is almost like 3.
>>
>> If you wanted assignment operator, it should have asymmetric precedence:
>>
>>     A + B := C + D
>>
>> is expected to be
>>
>>     A + (B := (C + D))
>>
>> Same is true for exponentiation operator. Most people would read
>>
>>     A**B**C
>>
>> as
>>
>>     A**(B**C)
>
> That's how I would parse it - right to left. I think that exponentiation
> is the only operator in my entire table which is right-to-left.

You could have pipelining operators:

"Buddy" >> Wide_Space >> "Hello" >> Stream

Also all prefix operators are right-to-left. Consider this:

* not 0x000FF0

(machine address inverted and then accessed)

Do you really want it to mutate into:

not (*X)

?

>> Splitting lattice operations into logical and bit-wise is
>> controversial. You would need two sets of and/or/not operators.
>
> That's no problem. I use symbols for bitwise and words for booleans. For
> consistency they both follow the same order: not, and, xor, or.
>
> In order of application they would be:
>
> Bitwise:
>   << >>   shifts
>   !       bitnot
>   &       bitand
>   %       bitxor
>   #       bitor
>
> Then, later:
>
> Boolean
>   not     logical not
>   and     logical and  (shortcutting)
>   xor     logical xor
>   or      logical or   (shortcutting)
>
>
>> If you want to mix "and" with "or" as C allows for && and ||, then
>> "and" is an equivalent of "*" and "or" is of "+". Compare:
>>
>>     x * 0 = 0    x and 0 = 0
>>     x + 0 = x    x or  0 = x
>>
>> So you could put bit-wise "and" into multiplicative and "or" into
>> additive operators.
>
> Sounds as though you and Bart are on the same page on taking a
> structural approach to precedences rather than a semantic one.

Yes, but for different reasons. In a higher level language syntax can
imply nothing about semantics. So, rather than provoking reader to wrong
conclusion, just define syntax completely separate of.

>>  But as I said it is rather controversial. I would just forbid mixing
>> arithmetic and lattice operators.
>>
>
> Fine. Though what would a programmer do if he had a genuine need to
> 'mix' them?

Require disambiguation per parenthesis.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smbl0f$qnf$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1187&group=comp.lang.misc#1187

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 16:58:57 +0000
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <smbl0f$qnf$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 Nov 2021 16:58:55 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5aecade92803dad329ae52332fcb0c0e";
logging-data="27375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+1Z3JmMFtByZkYgO4XK1BCDgldYCXrowk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Cancel-Lock: sha1:Y9a2RGi1iRGK9jRb68FXaQzPg98=
In-Reply-To: <smbjo6$17a2$1@gioia.aioe.org>
 by: Bart - Mon, 8 Nov 2021 16:58 UTC

On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
> On 2021-11-08 16:39, James Harris wrote:

>> (using ^ for exponentiation) because ^ has higher precedence than
>> prefix unary minus. Your mathematicians should be happy. :-)
>
> Traditionally in mathematics circumflex (hat) means something like
> "vector".

Unit-vectors IIRC. But that was applied over the variable.

> Using it for exponentiation was one of so many C's blunders.

C did make many blunders but this wasn't one of them. (It doesn't have
an exponentiaton operator, so avoided making one more!)

Perhaps ^ was supposed to look like an up-arrow:

https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation

But I don't know where using it for power-of originated. I use ^ to mean
pointer dereference, taken from Pascal. And ** for exponentiation,
probably taken from Fortran.

C uses ^ for bitwise XOR.

Re: Order of transformation of values

<smbn71$145h$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1188&group=comp.lang.misc#1188

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 18:36:34 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smbn71$145h$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="37041"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Mon, 8 Nov 2021 17:36 UTC

On 2021-11-08 17:58, Bart wrote:
> On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
>> On 2021-11-08 16:39, James Harris wrote:
>
>>> (using ^ for exponentiation) because ^ has higher precedence than
>>> prefix unary minus. Your mathematicians should be happy. :-)
>>
>> Traditionally in mathematics circumflex (hat) means something like
>> "vector".
>
> Unit-vectors IIRC. But that was applied over the variable.

Right, you type X <backspace> ^ and get it nicely printed over X on a
dot matrix printer. (:-))

> Perhaps ^ was supposed to look like an up-arrow:
>
> https://en.wikipedia.org/wiki/Knuth%27s_up-arrow_notation

Up-arrow makes sense as poor man's superscript.

> But I don't know where using it for power-of originated. I use ^ to mean
> pointer dereference, taken from Pascal.

I prefer implicit dereference.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smc3rt$in9$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1197&group=comp.lang.misc#1197

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 21:12:29 +0000
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <smc3rt$in9$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 Nov 2021 21:12:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ef109d65fb590c5ee86153aca0071591";
logging-data="19177"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/danPo49K9JOhcFGiwggzJdpJ3WHY/2zQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:paDvtgWwIzx8dZiw+TEIKMauy/o=
In-Reply-To: <smbn71$145h$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Mon, 8 Nov 2021 21:12 UTC

On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
> On 2021-11-08 17:58, Bart wrote:

....

>> But I don't know where using it for power-of originated. I use ^ to
>> mean pointer dereference, taken from Pascal.
>
> I prefer implicit dereference.
>

If pointers are implicitly dereferenced what do you do when you want to
get the pointer's value?

--
James Harris

Re: Order of transformation of values

<smc6ai$3tq$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1202&group=comp.lang.misc#1202

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 22:54:28 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smc6ai$3tq$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
<smc3rt$in9$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="4026"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Mon, 8 Nov 2021 21:54 UTC

On 2021-11-08 22:12, James Harris wrote:
> On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
>> On 2021-11-08 17:58, Bart wrote:
>
> ...
>
>>> But I don't know where using it for power-of originated. I use ^ to
>>> mean pointer dereference, taken from Pascal.
>>
>> I prefer implicit dereference.
>
> If pointers are implicitly dereferenced what do you do when you want to
> get the pointer's value?

Nothing dramatic. When the target has the pointer type then that is the
pointer's value. When the target has the target type then that is
dereferencing.

The problems arise with type inference or bottom-up stuff you and Bart
promote. But I want none of these.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smc9sb$ud8$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1207&group=comp.lang.misc#1207

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 8 Nov 2021 22:55:05 +0000
Organization: A noiseless patient Spider
Lines: 258
Message-ID: <smc9sb$ud8$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 8 Nov 2021 22:55:07 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="ef109d65fb590c5ee86153aca0071591";
logging-data="31144"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX189mc1lB54TaqVfvtH+cF1N7oWigWsSAg0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:H40NNOrQp/Ys+sNjiH/PHTaf4TE=
In-Reply-To: <smbjo6$17a2$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Mon, 8 Nov 2021 22:55 UTC

On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
> On 2021-11-08 16:39, James Harris wrote:
>> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:
>>> On 2021-11-08 12:21, James Harris wrote:
>>>
>>>> ATM I follow the latter (fourth) approach. My operators are
>>>> therefore in order (high to low)
>>>>
>>>>    1. Address manipulations (as in the other recent thread)
>>>>    2. Bit-pattern manipulation (&, !, etc)
>>>>    3. Arithmetic manipulation (+, *, etc)
>>>>    4. Comparisons (<, !=, etc)
>>>>    5. Logical manipulation (AND, NOT, etc)

....

>>> Which is why your rules make no sense in the first place:
>>>
>>>     A + not B
>>>
>>> is never
>>>
>>>     not (A + B)
>>>
>>> and
>>>
>>>     A * -B
>>>
>>> is never
>>>
>>>     - (A * B)
>>>
>>> And
>>>
>>>     - not A
>>>
>>> is never
>>>
>>>     not (-A)
>>
>> Those are strange examples. You say they'd never match but I wouldn't
>> expect them to.
>
> These are examples why unary operation should have higher precedence.

AFAICS having higher precedence does not mean rewriting the expression
with the operators in a different order! Take your first one, A + not B.
I would parse that as

A + (not B)

FWIW I'd parse the others as

A * (- B)
- (not A)

>
>>> should "not" really had lower precedence than "-".
>>
>> Well, think of
>>
>>    not A > B
>>    not A <= - F()
>
> Even when not is bit-wise?
>
>    not A + B * C + D

For bitwise not I use ! so

! A + B * C + D

which as the bitwise operators have high precedence would parse as

(! A) + (B * C) + D

Boolean operators have low precedence so boolean not would parse as

not (A + (B * C) + D)

>
> And you have the problem of mixing unary operators having different
> precedence:
>
>    - not A
>
> E.g. in
>
>    - not A + B * C + D
>
> It is inconsistent.

Where's the inconsistency? If you mean bitnot that would parse as

(- (! A)) + (B * C) + D

....

>>> The natural precedence used by sane languages:
>>>
>>> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
>>> 2. Indexing
>>
>> Why split namespace and indexing when the operations can be mixed
>> freely? E.g.
>>
>>    X[i].field.subfield[j].datum
>
> Compare:
>
>    field.subfield[j]  --->  (field.subfield)[j]
>
> with
>
>    field+subfield[j]  --->  field + (subfield[j])

Arithmetic + is neither namespace nor indexing so I don't see the point.

....

>>> 4. Dyadic operators
>>>    4.1. Exponentiation (**)
>>>    4.2. Multiplicative (*, /)
>>>    4.3. Additive (+, -)
>>>    4.4. Comparisons (<, >, =)
>>>    4.5. Lattice (and, or, xor)
>>
>> Most of those are standard. I have
>>
>>    ^    exponentiation
>>    +-   monadic plus and minus
>>    */   times, divide, remainder etc
>>    +-   dyadic plus and minus
>>    ...  all the comparison operators with one precedence
>>    ...  all the boolean operators with their own precedences
>>
>>>
>>> 4.1 would conflict with 3 for most readers with background in
>>> mathematics:
>>>
>>>     -A**B
>>
>> I would parse that 'correctly' as
>>
>>    - (A ^ B)
>
> To me it is not obvious, why not
>
>    (-A) ^ B?

Three reasons:

1. Because ^ has higher precedence than unary minus.

2. Because that's the ordering used in maths.

3. Because the sign will be lost if raised to an even power.

>
> And the counter example is this:
>
>    A ^ -B

I would parse as

A ^ (- B)

>
> If ^ preceded -, then that should too become
>
>    -(A ^ B)

As mentioned above, I don't see why you would rearrange the operators.

>
> My choice would be allow
>
>    A ^ -B  ---> A ^ (-B)
>    -A ^ B  ---> Syntax error, give me parenthesis.

I do the first. The second is - (A ^ B). Not sure why you would want
that to be a syntax error.

>
> So, unary always precedes dyadic, except the metas.

Understood but 'metas' such as . ( [ * and & can be normal operators. No
need to parse them separately.

....

>>>     A**(B**C)
>>
>> That's how I would parse it - right to left. I think that
>> exponentiation is the only operator in my entire table which is
>> right-to-left.
>
> You could have pipelining operators:
>
>    "Buddy" >> Wide_Space >> "Hello" >> Stream

I don't know what they are but it doesn't matter. I can make any
operator right associative just by making its precedence an odd number.

>
> Also all prefix operators are right-to-left. Consider this:
>
>    * not 0x000FF0
>
> (machine address inverted and then accessed)

I don't know that L-R or R-L applies to prefix or postfix operators.

To bitwise invert that address and then dereference it I would use
something like

(! 16'000FF0')*

>
> Do you really want it to mutate into:
>
>    not (*X)
>
> ?

Again you are rearranging operators! Maybe I'm too tired to think but I
don't recall that ever being a thing.

....

>>>  But as I said it is rather controversial. I would just forbid mixing
>>> arithmetic and lattice operators.
>>>
>>
>> Fine. Though what would a programmer do if he had a genuine need to
>> 'mix' them?
>
> Require disambiguation per parenthesis.
>

Do you mean so that

A + B and C - D

would become either

(A + B) and (C - D)

or

A + (B and C) - D

?

--
James Harris

Re: Order of transformation of values

<smdcqb$19br$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1215&group=comp.lang.misc#1215

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Tue, 9 Nov 2021 09:51:22 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smdcqb$19br$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="42363"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Tue, 9 Nov 2021 08:51 UTC

On 2021-11-08 23:55, James Harris wrote:
> On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
>> On 2021-11-08 16:39, James Harris wrote:
>>> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:
>>>> On 2021-11-08 12:21, James Harris wrote:
>>>>
>>>>> ATM I follow the latter (fourth) approach. My operators are
>>>>> therefore in order (high to low)
>>>>>
>>>>>    1. Address manipulations (as in the other recent thread)
>>>>>    2. Bit-pattern manipulation (&, !, etc)
>>>>>    3. Arithmetic manipulation (+, *, etc)
>>>>>    4. Comparisons (<, !=, etc)
>>>>>    5. Logical manipulation (AND, NOT, etc)
>
> ...
>
>>>> Which is why your rules make no sense in the first place:
>>>>
>>>>     A + not B
>>>>
>>>> is never
>>>>
>>>>     not (A + B)
>>>>
>>>> and
>>>>
>>>>     A * -B
>>>>
>>>> is never
>>>>
>>>>     - (A * B)
>>>>
>>>> And
>>>>
>>>>     - not A
>>>>
>>>> is never
>>>>
>>>>     not (-A)
>>>
>>> Those are strange examples. You say they'd never match but I wouldn't
>>> expect them to.
>>
>> These are examples why unary operation should have higher precedence.
>
> AFAICS having higher precedence does not mean rewriting the expression
> with the operators in a different order! Take your first one, A + not B.
> I would parse that as
>
>   A + (not B)

I see the source of confusion. You want to have the precedence on the
right side of "not" very low, but the one on the left side is very high.
That gives you:

A + not B + C ---> A + (not (B + C))

When *both* sides are low, the result is

A + not B + C ---> not ((A + B) + C)

So, when you said low precedence you meant only the right side of.

I prefer balanced precedences for unary operations (both very high):

A + not B + C ---> A + (not B) + C

>>>> The natural precedence used by sane languages:
>>>>
>>>> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
>>>> 2. Indexing
>>>
>>> Why split namespace and indexing when the operations can be mixed
>>> freely? E.g.
>>>
>>>    X[i].field.subfield[j].datum
>>
>> Compare:
>>
>>     field.subfield[j]  --->  (field.subfield)[j]
>>
>> with
>>
>>     field+subfield[j]  --->  field + (subfield[j])
>
> Arithmetic + is neither namespace nor indexing so I don't see the point.

The point is that "." has a higher precedence than [] and "+" has a
lower one. You cannot have them in the same class.

> ...
>
>>>> 4. Dyadic operators
>>>>    4.1. Exponentiation (**)
>>>>    4.2. Multiplicative (*, /)
>>>>    4.3. Additive (+, -)
>>>>    4.4. Comparisons (<, >, =)
>>>>    4.5. Lattice (and, or, xor)
>>>
>>> Most of those are standard. I have
>>>
>>>    ^    exponentiation
>>>    +-   monadic plus and minus
>>>    */   times, divide, remainder etc
>>>    +-   dyadic plus and minus
>>>    ...  all the comparison operators with one precedence
>>>    ...  all the boolean operators with their own precedences
>>>
>>>>
>>>> 4.1 would conflict with 3 for most readers with background in
>>>> mathematics:
>>>>
>>>>     -A**B
>>>
>>> I would parse that 'correctly' as
>>>
>>>    - (A ^ B)
>>
>> To me it is not obvious, why not
>>
>>     (-A) ^ B?
>
> Three reasons:
>
> 1. Because ^ has higher precedence than unary minus.

But sir, it has a lower precedence! (:-))

> 2. Because that's the ordering used in maths.

Well, in mathematics it would be

-Aᵇ

There is no confusion because B is in superscript.

> 3. Because the sign will be lost if raised to an even power.

B looks very uneven today. (:-))

>> My choice would be allow
>>
>>     A ^ -B  ---> A ^ (-B)
>>     -A ^ B  ---> Syntax error, give me parenthesis.
>
> I do the first. The second is - (A ^ B). Not sure why you would want
> that to be a syntax error.

Because with *balanced* precedences it would mean (-A)^B.
>> So, unary always precedes dyadic, except the metas.
>
> Understood but 'metas' such as . ( [ * and & can be normal operators. No
> need to parse them separately.

Sure.

>>>>     A**(B**C)
>>>
>>> That's how I would parse it - right to left. I think that
>>> exponentiation is the only operator in my entire table which is
>>> right-to-left.
>>
>> You could have pipelining operators:
>>
>>     "Buddy" >> Wide_Space >> "Hello" >> Stream
>
> I don't know what they are but it doesn't matter.

Just an example of another right-to-left operator.

> I can make any
> operator right associative just by making its precedence an odd number.

You could use unbalanced precedences, since you already have them. For a
dyadic operator op:

left precedence > right precedence

X op Y op Z ---> X op<<Y op Z ---> (X op Y) op Z

left precedence < right precedence

X op Y op Z ---> X op Y>>op Z ---> X op (Y op Z)

>>> Fine. Though what would a programmer do if he had a genuine need to
>>> 'mix' them?
>>
>> Require disambiguation per parenthesis.
>
> Do you mean so that
>
>   A + B and C - D
>
> would become either
>
>   (A + B) and (C - D)
>
> or
>
>   A + (B and C) - D

I mean flagging any confusing syntax illegal and require the programmer
to clarify thigs using parenthesis.

Answering your question, to me

A + B and C - D

reads like

(A + B) and (C - D)

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smdkfl$h7e$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1221&group=comp.lang.misc#1221

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Tue, 9 Nov 2021 11:02:12 +0000
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <smdkfl$h7e$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
<smc3rt$in9$1@dont-email.me> <smc6ai$3tq$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 Nov 2021 11:02:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="67963263ba017c4a2e5d280dc041c34d";
logging-data="17646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181Ox0A/N0lmOrDVArMjhlPSzjud8FlZe8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:fkoUCa0qkBAu1VyaqHgUptM/2Zo=
In-Reply-To: <smc6ai$3tq$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Tue, 9 Nov 2021 11:02 UTC

On 08/11/2021 21:54, Dmitry A. Kazakov wrote:
> On 2021-11-08 22:12, James Harris wrote:
>> On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
>>> On 2021-11-08 17:58, Bart wrote:
>>
>> ...
>>
>>>> But I don't know where using it for power-of originated. I use ^ to
>>>> mean pointer dereference, taken from Pascal.
>>>
>>> I prefer implicit dereference.
>>
>> If pointers are implicitly dereferenced what do you do when you want
>> to get the pointer's value?
>
> Nothing dramatic. When the target has the pointer type then that is the
> pointer's value. When the target has the target type then that is
> dereferencing.
>
> The problems arise with type inference or bottom-up stuff you and Bart
> promote. But I want none of these.
>

I don't follow. If n is a reference or pointer to a node then I presume
you want to refer to the node as

n

but what if you want the value of n, e.g. to print it, rather than the
value of the node it points at?

I ask because I have thought of allowing a programmer to make some
pointers auto dereferencing but I recognise that in some situations a
programmer might want to access the value of the pointer rather than the
value of what it points at.

--
James Harris

Re: Order of transformation of values

<smdmut$kje$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1224&group=comp.lang.misc#1224

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Tue, 9 Nov 2021 12:44:28 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smdmut$kje$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
<smc3rt$in9$1@dont-email.me> <smc6ai$3tq$1@gioia.aioe.org>
<smdkfl$h7e$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="21102"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
 by: Dmitry A. Kazakov - Tue, 9 Nov 2021 11:44 UTC

On 2021-11-09 12:02, James Harris wrote:
> On 08/11/2021 21:54, Dmitry A. Kazakov wrote:
>> On 2021-11-08 22:12, James Harris wrote:
>>> On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
>>>> On 2021-11-08 17:58, Bart wrote:
>>>
>>> ...
>>>
>>>>> But I don't know where using it for power-of originated. I use ^ to
>>>>> mean pointer dereference, taken from Pascal.
>>>>
>>>> I prefer implicit dereference.
>>>
>>> If pointers are implicitly dereferenced what do you do when you want
>>> to get the pointer's value?
>>
>> Nothing dramatic. When the target has the pointer type then that is
>> the pointer's value. When the target has the target type then that is
>> dereferencing.
>>
>> The problems arise with type inference or bottom-up stuff you and Bart
>> promote. But I want none of these.
>>
>
> I don't follow. If n is a reference or pointer to a node then I presume
> you want to refer to the node as
>
>   n
>
> but what if you want the value of n, e.g. to print it, rather than the
> value of the node it points at?

You mean have two overloaded functions:

function Image (X : Node) return String;
function Image (X : Node_Ptr) return String;

Both would apply to n (of the type Node_Ptr). Right?

In that case you would have to disambiguate

Image (n)

E.g. in Ada you would use a qualified expression:

Image (Node_Ptr'(n)) -- Pointer to string
Image (Node'(n)) -- Node to string

or a fully qualified name of Image if they are declared in different
modules or whatever other method of resolving conflicting overloads in
your language.

Furthermore you can decide that

function Image (X : Node) return String;

*overrides*

function Image (X : Node_Ptr) return String;

(remember that pesky OO?) and therefore

Image (n)

is unambiguous and means

Image (Node'(n))

Then if the programmer wanted rather the overridden meaning, he would
have to qualify it:

Image (Node_Ptr'(n))

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smg03u$ea7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1242&group=comp.lang.misc#1242

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Wed, 10 Nov 2021 08:33:01 +0000
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <smg03u$ea7$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me> <smdcqb$19br$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 10 Nov 2021 08:33:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b05cfa0f087b5bca78f4a91c981d63c7";
logging-data="14663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/aW3zpc2umgOiRGtWBqaJgAyivStXCp4M="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:4F+vL/MAx9kDSaTGy2PSTB7y+Cw=
In-Reply-To: <smdcqb$19br$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Wed, 10 Nov 2021 08:33 UTC

On 09/11/2021 08:51, Dmitry A. Kazakov wrote:
> On 2021-11-08 23:55, James Harris wrote:
>> On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
>>> On 2021-11-08 16:39, James Harris wrote:
>>>> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:

....

>>>>> The natural precedence used by sane languages:
>>>>>
>>>>> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
>>>>> 2. Indexing
>>>>
>>>> Why split namespace and indexing when the operations can be mixed
>>>> freely? E.g.
>>>>
>>>>    X[i].field.subfield[j].datum
>>>
>>> Compare:
>>>
>>>     field.subfield[j]  --->  (field.subfield)[j]
>>>
>>> with
>>>
>>>     field+subfield[j]  --->  field + (subfield[j])
>>
>> Arithmetic + is neither namespace nor indexing so I don't see the point.
>
> The point is that "." has a higher precedence than [] and "+" has a
> lower one. You cannot have them in the same class.

In your example both . and [] have higher precedence than + so + is
irrelevant to whether . and [] should be in the same or different
precedence levels. Further, both . and [] are postfix. Therefore you
could have a chain of them such as

<OP> X.field1[i].field2[j].field3[k]

and that chain will extend for as long as the precedence of . or [] is
higher than the precedence of the operator to the left variable X which
I've called <OP>. Now, if . and [] have higher precedence than all
others which could appear to the left of the variable name (which in
your scheme they do) then however long the chain is all of it will be
applied before <OP>. Therefore I put it to you that they do not have to
have separate priority levels.

It's easiest to see with a priority diagram. Digits indicate precedences
of operators and v is a variable. If you have

5v787878

then all of the 7s and 8s will be applied (one at a time, and left to
right because they are trailing operators) before the 5.

Am not ignoring other points in your post but will have to come back to
them.

--
James Harris

Re: Order of transformation of values

<smg553$o3k$1@gioia.aioe.org>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1244&group=comp.lang.misc#1244

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!aioe.org!PWxlC/luZAoWELvf51vawQ.user.46.165.242.91.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Wed, 10 Nov 2021 10:59:01 +0100
Organization: Aioe.org NNTP Server
Message-ID: <smg553$o3k$1@gioia.aioe.org>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me> <smdcqb$19br$1@gioia.aioe.org>
<smg03u$ea7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="24692"; posting-host="PWxlC/luZAoWELvf51vawQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.0
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: Dmitry A. Kazakov - Wed, 10 Nov 2021 09:59 UTC

On 2021-11-10 09:33, James Harris wrote:
> On 09/11/2021 08:51, Dmitry A. Kazakov wrote:
>> On 2021-11-08 23:55, James Harris wrote:
>>> On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
>>>> On 2021-11-08 16:39, James Harris wrote:
>>>>> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:
>
> ...
>
>>>>>> The natural precedence used by sane languages:
>>>>>>
>>>>>> 1. Namespace, member extraction A.B[C]  means "[]"("."(A,B),C)
>>>>>> 2. Indexing
>>>>>
>>>>> Why split namespace and indexing when the operations can be mixed
>>>>> freely? E.g.
>>>>>
>>>>>    X[i].field.subfield[j].datum
>>>>
>>>> Compare:
>>>>
>>>>     field.subfield[j]  --->  (field.subfield)[j]
>>>>
>>>> with
>>>>
>>>>     field+subfield[j]  --->  field + (subfield[j])
>>>
>>> Arithmetic + is neither namespace nor indexing so I don't see the point.
>>
>> The point is that "." has a higher precedence than [] and "+" has a
>> lower one. You cannot have them in the same class.
>
> In your example both . and [] have higher precedence than + so + is
> irrelevant to whether . and [] should be in the same or different
> precedence levels. Further, both . and [] are postfix.

? "." is obviously dyadic. [] is not an operator.

There is no such thing as "same" precedence, in the end you must always
decide which one takes over:

A.B[C] "." takes precedence over []
A+B[C] [] takes precedence over +

On the second thought, you could argue that . and [] have same "base
precedence" combined with the left-to-right rule like in the case of "+"
and "-". That should work, I guess.

> Therefore you
> could have a chain of them such as
>
>   <OP> X.field1[i].field2[j].field3[k]
>
> and that chain will extend for as long as the precedence of . or [] is
> higher than the precedence of the operator to the left variable X which
> I've called <OP>. Now, if . and [] have higher precedence than all
> others which could appear to the left of the variable name (which in
> your scheme they do) then however long the chain is all of it will be
> applied before <OP>.

Irrelevant to the issue whether

X.field1[i].field2[j].field3[k]

means

(((X.field1)[i].field2)[j].field3)[k]

or

((X.(field1[i])).(field2[j])).(field3[k])

or something else.

But OK, I think one could put them together as long left-to-right holds.

--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

Re: Order of transformation of values

<smg9n6$bo7$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1246&group=comp.lang.misc#1246

  copy link   Newsgroups: comp.lang.misc sljfsdjfl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc,sljfsdjfl
Subject: Re: Order of transformation of values
Date: Wed, 10 Nov 2021 11:16:53 +0000
Organization: A noiseless patient Spider
Lines: 143
Message-ID: <smg9n6$bo7$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me> <smdcqb$19br$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 10 Nov 2021 11:16:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b05cfa0f087b5bca78f4a91c981d63c7";
logging-data="12039"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+DznsNiO+11hpwMOULDc0oC0+GwtKuQGM="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:wnpVSLxocqWomQesawQyMebulco=
In-Reply-To: <smdcqb$19br$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Wed, 10 Nov 2021 11:16 UTC

On 09/11/2021 08:51, Dmitry A. Kazakov wrote:
> On 2021-11-08 23:55, James Harris wrote:
>> On 08/11/2021 16:37, Dmitry A. Kazakov wrote:
>>> On 2021-11-08 16:39, James Harris wrote:
>>>> On 08/11/2021 12:29, Dmitry A. Kazakov wrote:

....

>>> These are examples why unary operation should have higher precedence.
>>
>> AFAICS having higher precedence does not mean rewriting the expression
>> with the operators in a different order! Take your first one, A + not
>> B. I would parse that as
>>
>>    A + (not B)
>
> I see the source of confusion.

You say that to raise my hopes only to dash them in the next sentence! :-(

> You want to have the precedence on the
> right side of "not" very low, but the one on the left side is very high.

No, not at all!

I am finding this a fascinating subthread because I have been completely
baffled as to what you have in mind and I suspect you are thinking the
same about me. But there has to be a way through.

On precedences I did, many years ago, look at parsing an expression by
giving operators different precedences on left and right (there is at
least one parsing algorithm which espouses that approach) but I chose
not to. All of my operators have just one precedence.

That still leaves the confusion. However, ...

> That gives you:
>
>    A + not B + C  --->  A + (not (B + C))
>
> When *both* sides are low, the result is
>
>    A + not B + C  --->  not ((A + B) + C)

I think I may have realised where the confusion is coming from. Some key
points:

Are you aware that expressions (as we typically use them) have two
contexts? One might call them prefix and postfix.

prefix - pre a subexpression, looking for a value
postfix - post a subexpression, looking for an operator

A valid subexpression needs

one prefix phase
zero or more postfix phases

E.g. the subexpression

X

has the required prefix phase (ending in a value) and zero postfix phases.

As for the /extent/ of a subexpression, in simple terms a subexpression
ends when we get to an operator of lower precedence than the context in
which the subexpression began. For example, in

A / B ** C + D

the internal subexpression B ** C ends after C because + has lower
precedence than /.

In fact, with left-associative operators it is more accurate to say that
a subexpression ends when we encounter an operator whose precedence is
less than or equal to the precedence with which the subexpression began,
and it is convenient to say that the end of the entire expression has
precedence 0 so that is also automatically recognised as the end of any
subexpression.

Finally, operators which appear in the prefix phase cannot end an
expression because they do not satisfy the requirement that the prefix
phase has to result in a value. But they can call the expression parser
to resolve what follows then apply their operations to the result and
thus end that phase (and potentially the entire expression) with a value.

Still with me? If it seems strange please reread. This is all standard
expression parsing as may be used in Ada, Basic, C, etc.

To avoid making this post any longer maybe I should stop here. Can you
see how the above allows your example expression to be parsed
irrespective of whether 'not' has higher or lower precedence than the
operators which surround it?

....

>>>>>     -A**B
>>>>
>>>> I would parse that 'correctly' as
>>>>
>>>>    - (A ^ B)
>>>
>>> To me it is not obvious, why not
>>>
>>>     (-A) ^ B?
>>
>> Three reasons:
>>
>> 1. Because ^ has higher precedence than unary minus.
>
> But sir, it has a lower precedence! (:-))

^^^^^
I've found the unbalanced parentheses you keep talking about! ;-)

I have exponentiation as having higher precedence than unary minus.
Parsed as per the comments above.

>
>> 2. Because that's the ordering used in maths.
>
> Well, in mathematics it would be
>
>    -Aᵇ
>
> There is no confusion because B is in superscript.

Yes, so AISI - A ^ B shoulc be - (A ^ B) as in maths.

>
>> 3. Because the sign will be lost if raised to an even power.
>
> B looks very uneven today. (:-))

Some days are like that! But B is often a constant (and often 2).

To cut down the post a but I've snipped a lot of examples but feel free
to come back to them.

--
James Harris

Re: Order of transformation of values

<smgams$ib6$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1247&group=comp.lang.misc#1247

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Wed, 10 Nov 2021 11:33:48 +0000
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <smgams$ib6$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me> <smdcqb$19br$1@gioia.aioe.org>
<smg03u$ea7$1@dont-email.me> <smg553$o3k$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 10 Nov 2021 11:33:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b05cfa0f087b5bca78f4a91c981d63c7";
logging-data="18790"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/q76lokqJppdYQikw8a3d5GHFVEaRvU8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:Cmcv/ps5xVdTQy/32/CaoiiXrjM=
In-Reply-To: <smg553$o3k$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Wed, 10 Nov 2021 11:33 UTC

On 10/11/2021 09:59, Dmitry A. Kazakov wrote:

....

> ? "." is obviously dyadic. [] is not an operator.

Agreed, though [ can be parsed in part as a dyadic operator.

>
> There is no such thing as "same" precedence, in the end you must always
> decide which one takes over:
>
>    A.B[C]   "." takes precedence over []
>    A+B[C]   [] takes precedence over +
>
> On the second thought, you could argue that . and [] have same "base
> precedence" combined with the left-to-right rule like in the case of "+"
> and "-". That should work, I guess.

Yes. I would add that the tie has to be broken by an associativity rule
even in the case when a certain 'operator' can be repeated as in either of

A.B.C
A[B][C]

....

> But OK, I think one could put them together as long left-to-right holds.

Agreed.

--
James Harris

Re: Order of transformation of values

<smgdqu$8fl$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1249&group=comp.lang.misc#1249

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Wed, 10 Nov 2021 12:27:09 +0000
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <smgdqu$8fl$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smc9sb$ud8$1@dont-email.me> <smdcqb$19br$1@gioia.aioe.org>
<smg9n6$bo7$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Nov 2021 12:27:10 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b05cfa0f087b5bca78f4a91c981d63c7";
logging-data="8693"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ranLjJEvfLg1JzFT5L8O971Dp9lWUDoQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.13.0
Cancel-Lock: sha1:rX4YXnyi+UUg6uVf1FMoe0rUBFY=
In-Reply-To: <smg9n6$bo7$1@dont-email.me>
Content-Language: en-GB
 by: James Harris - Wed, 10 Nov 2021 12:27 UTC

On 10/11/2021 11:16, James Harris wrote:

To anyone replying please beware of a reply to all newsgroups. I
sometimes enter a rubbish string as 'an additional newsgroup to reply
to' so that I cannot send the message by mistake (some
too-easy-to-press-by-mistake key combinations of my newsreader do that).
However, in this case the message went even with the rubbish string
(sljfsdjfl) in place. I don't know why, or where that message would have
gone other than to comp.lang.misc but it's probably nowhere useful!

--
James Harris

Re: Order of transformation of values

<su8t5o$9ai$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1786&group=comp.lang.misc#1786

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Sat, 12 Feb 2022 18:10:00 +0000
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <su8t5o$9ai$2@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
<smc3rt$in9$1@dont-email.me> <smc6ai$3tq$1@gioia.aioe.org>
<smdkfl$h7e$1@dont-email.me> <smdmut$kje$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Feb 2022 18:10:00 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b36d7cd7a2226d888bf6546c38de8278";
logging-data="9554"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RX7nnLf0w+RPPv6yHPogyaJlrpnDiLOY="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:l+Z7RHs27tzMOGUa4XwloVQnd9g=
In-Reply-To: <smdmut$kje$1@gioia.aioe.org>
Content-Language: en-GB
 by: James Harris - Sat, 12 Feb 2022 18:10 UTC

On 09/11/2021 11:44, Dmitry A. Kazakov wrote:
> On 2021-11-09 12:02, James Harris wrote:
>> On 08/11/2021 21:54, Dmitry A. Kazakov wrote:
>>> On 2021-11-08 22:12, James Harris wrote:
>>>> On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
>>>>> On 2021-11-08 17:58, Bart wrote:
>>>>
>>>> ...
>>>>
>>>>>> But I don't know where using it for power-of originated. I use ^
>>>>>> to mean pointer dereference, taken from Pascal.
>>>>>
>>>>> I prefer implicit dereference.
>>>>
>>>> If pointers are implicitly dereferenced what do you do when you want
>>>> to get the pointer's value?
>>>
>>> Nothing dramatic. When the target has the pointer type then that is
>>> the pointer's value. When the target has the target type then that is
>>> dereferencing.
>>>
>>> The problems arise with type inference or bottom-up stuff you and
>>> Bart promote. But I want none of these.
>>>
>>
>> I don't follow. If n is a reference or pointer to a node then I
>> presume you want to refer to the node as
>>
>>    n
>>
>> but what if you want the value of n, e.g. to print it, rather than the
>> value of the node it points at?

That's not what I was thinking but it's an interesting idea.

--
James Harris

Re: Order of transformation of values

<su8uma$l3m$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1788&group=comp.lang.misc#1788

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: james.harris.1@gmail.com (James Harris)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Sat, 12 Feb 2022 18:35:53 +0000
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <su8uma$l3m$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me> <smb57g$1qi6$1@gioia.aioe.org>
<smbgc6$kh7$1@dont-email.me> <smbjo6$17a2$1@gioia.aioe.org>
<smbl0f$qnf$1@dont-email.me> <smbn71$145h$1@gioia.aioe.org>
<smc3rt$in9$1@dont-email.me> <smc6ai$3tq$1@gioia.aioe.org>
<smdkfl$h7e$1@dont-email.me> <smdmut$kje$1@gioia.aioe.org>
<su8t5o$9ai$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Feb 2022 18:35:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="b36d7cd7a2226d888bf6546c38de8278";
logging-data="21622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ga7cWMBvWO59xkD8Qca6g76N/FoLuofU="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Thunderbird/91.5.0
Cancel-Lock: sha1:mLQFCiXDTW2J0gc0kDPZYo0657s=
In-Reply-To: <su8t5o$9ai$2@dont-email.me>
Content-Language: en-GB
 by: James Harris - Sat, 12 Feb 2022 18:35 UTC

On 12/02/2022 18:10, James Harris wrote:
> On 09/11/2021 11:44, Dmitry A. Kazakov wrote:
>> On 2021-11-09 12:02, James Harris wrote:
>>> On 08/11/2021 21:54, Dmitry A. Kazakov wrote:
>>>> On 2021-11-08 22:12, James Harris wrote:
>>>>> On 08/11/2021 17:36, Dmitry A. Kazakov wrote:
>>>>>> On 2021-11-08 17:58, Bart wrote:
>>>>>
>>>>> ...
>>>>>
>>>>>>> But I don't know where using it for power-of originated. I use ^
>>>>>>> to mean pointer dereference, taken from Pascal.
>>>>>>
>>>>>> I prefer implicit dereference.
>>>>>
>>>>> If pointers are implicitly dereferenced what do you do when you
>>>>> want to get the pointer's value?
>>>>
>>>> Nothing dramatic. When the target has the pointer type then that is
>>>> the pointer's value. When the target has the target type then that
>>>> is dereferencing.
>>>>
>>>> The problems arise with type inference or bottom-up stuff you and
>>>> Bart promote. But I want none of these.
>>>>
>>>
>>> I don't follow. If n is a reference or pointer to a node then I
>>> presume you want to refer to the node as
>>>
>>>    n
>>>
>>> but what if you want the value of n, e.g. to print it, rather than
>>> the value of the node it points at?
>
> That's not what I was thinking but it's an interesting idea.

Oops, I cut off the part I meant to reply to. It was Dmitry's suggestion
of supplying the reference/pointer in each case but overloading two
functions, one which accessed the pointer itself and another which
followed the pointer to access its referent.

--
James Harris

Re: Order of transformation of values

<927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1791&group=comp.lang.misc#1791

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:a05:622a:4cb:: with SMTP id q11mr7665790qtx.597.1644790957211;
Sun, 13 Feb 2022 14:22:37 -0800 (PST)
X-Received: by 2002:a05:620a:2483:: with SMTP id i3mr5713575qkn.339.1644790957069;
Sun, 13 Feb 2022 14:22:37 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Sun, 13 Feb 2022 14:22:36 -0800 (PST)
In-Reply-To: <smb189$qs8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.4.130.174; posting-account=r_UqYQoAAADroB0Qe_EzH25J5Oyuce4G
NNTP-Posting-Host: 24.4.130.174
References: <smb189$qs8$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>
Subject: Re: Order of transformation of values
From: alexfrunews@gmail.com (Alexei A. Frounze)
Injection-Date: Sun, 13 Feb 2022 22:22:37 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 30
 by: Alexei A. Frounze - Sun, 13 Feb 2022 22:22 UTC

On Monday, November 8, 2021 at 3:21:47 AM UTC-8, James Harris wrote:
[Again, joining late, haven't read all of the conversation.]
....
> ATM I follow the latter (fourth) approach. My operators are therefore in
> order (high to low)
>
> 1. Address manipulations (as in the other recent thread)
> 2. Bit-pattern manipulation (&, !, etc)
> 3. Arithmetic manipulation (+, *, etc)
> 4. Comparisons (<, !=, etc)
> 5. Logical manipulation (AND, NOT, etc)
....

If I were to redo C's "operator precedence", which is flawed for historical
reasons (B and/or BCPL to Blame, handy!), I'd reduce the total number of
the levels in the binary operators (fewer to remember):
1. *, /, %, <<, >>, &
(* and << kinda multiply, / and >> kinda divide, % and & kinda compute modulo,
* and & also kinda multiply)
2. +, -, |, ^
(+, | and ^ kinda add)
3. ==, !=, <=, <, >, >=
(no good reason to separate these)
4. &&
5. ||
6. ?:
I'd likely make =, +=, ++ and such non-expressions and drop the comma
operator altogether.
I'd probably rework ?: as well (make it left-associative), not entirely sure.

Alex

Re: Order of transformation of values

<suc9te$8sr$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1792&group=comp.lang.misc#1792

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 14 Feb 2022 01:05:50 +0000
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <suc9te$8sr$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me>
<927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Feb 2022 01:05:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4744014386d56013812bebf9afd11750";
logging-data="9115"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h/EV38Y5YY9gP8POEOh8ESKKxW8qfjTo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.5.1
Cancel-Lock: sha1:f7aDQAMMsOnW+xG44VHaMl9Yjvo=
In-Reply-To: <927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>
 by: Bart - Mon, 14 Feb 2022 01:05 UTC

On 13/02/2022 22:22, Alexei A. Frounze wrote:
> On Monday, November 8, 2021 at 3:21:47 AM UTC-8, James Harris wrote:
> [Again, joining late, haven't read all of the conversation.]
> ...
>> ATM I follow the latter (fourth) approach. My operators are therefore in
>> order (high to low)
>>
>> 1. Address manipulations (as in the other recent thread)
>> 2. Bit-pattern manipulation (&, !, etc)
>> 3. Arithmetic manipulation (+, *, etc)
>> 4. Comparisons (<, !=, etc)
>> 5. Logical manipulation (AND, NOT, etc)
> ...
>
> If I were to redo C's "operator precedence", which is flawed for historical
> reasons (B and/or BCPL to Blame, handy!), I'd reduce the total number of
> the levels in the binary operators (fewer to remember):
> 1. *, /, %, <<, >>, &
> (* and << kinda multiply, / and >> kinda divide, % and & kinda compute modulo,
> * and & also kinda multiply)
> 2. +, -, |, ^
> (+, | and ^ kinda add)
> 3. ==, !=, <=, <, >, >=
> (no good reason to separate these)
> 4. &&
> 5. ||
> 6. ?:
> I'd likely make =, +=, ++ and such non-expressions and drop the comma
> operator altogether.
> I'd probably rework ?: as well (make it left-associative), not entirely sure.

This is not far off the groupings I use. For the operators listed (and
using those same names), they are:

1 * / % << >> (shifts scale the value)

2 + - & | ^ (all bitwise ops are the same; they don't scale, so
they belong neither above or below, so why not here)

3 == != <= < > >=

4 &&

5 !!

For ?:, I have that as syntax, not an operator, and it requires
parentheses: ( a ? b : c), so that precedence is never an issue.

But it is very easy to improve on C.

> 3. ==, !=, <=, <, >, >=
> (no good reason to separate these)

People do come up with rationales for C having them in two groups (and
for having & | ^ at different levels) apparently every bad decision in C
has a benefit if you look hard enough; everything is a feature!

Re: Order of transformation of values

<4cf1e65d-a2a0-478b-b4ea-265755fa38b2n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1793&group=comp.lang.misc#1793

  copy link   Newsgroups: comp.lang.misc
X-Received: by 2002:ad4:5f4c:: with SMTP id p12mr8010159qvg.114.1644804108492;
Sun, 13 Feb 2022 18:01:48 -0800 (PST)
X-Received: by 2002:a05:6214:21cb:: with SMTP id d11mr8235051qvh.97.1644804108222;
Sun, 13 Feb 2022 18:01:48 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.misc
Date: Sun, 13 Feb 2022 18:01:48 -0800 (PST)
In-Reply-To: <suc9te$8sr$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=24.4.130.174; posting-account=r_UqYQoAAADroB0Qe_EzH25J5Oyuce4G
NNTP-Posting-Host: 24.4.130.174
References: <smb189$qs8$1@dont-email.me> <927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>
<suc9te$8sr$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4cf1e65d-a2a0-478b-b4ea-265755fa38b2n@googlegroups.com>
Subject: Re: Order of transformation of values
From: alexfrunews@gmail.com (Alexei A. Frounze)
Injection-Date: Mon, 14 Feb 2022 02:01:48 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 53
 by: Alexei A. Frounze - Mon, 14 Feb 2022 02:01 UTC

On Sunday, February 13, 2022 at 5:05:51 PM UTC-8, Bart wrote:
> On 13/02/2022 22:22, Alexei A. Frounze wrote:
> > If I were to redo C's "operator precedence", which is flawed for historical
> > reasons (B and/or BCPL to Blame, handy!), I'd reduce the total number of
> > the levels in the binary operators (fewer to remember):
> > 1. *, /, %, <<, >>, &
> > (* and << kinda multiply, / and >> kinda divide, % and & kinda compute modulo,
> > * and & also kinda multiply)
> > 2. +, -, |, ^
> > (+, | and ^ kinda add)
> > 3. ==, !=, <=, <, >, >=
> > (no good reason to separate these)
> > 4. &&
> > 5. ||
> > 6. ?:
> > I'd likely make =, +=, ++ and such non-expressions and drop the comma
> > operator altogether.
> > I'd probably rework ?: as well (make it left-associative), not entirely sure.
> This is not far off the groupings I use. For the operators listed (and
> using those same names), they are:
>
> 1 * / % << >> (shifts scale the value)
>
> 2 + - & | ^ (all bitwise ops are the same; they don't scale, so
> they belong neither above or below, so why not here)

If I view bitwise operator operands as just collections of individual/
independent bits, then separating & from | (and ^) lets me use the
same precedence as often used in computer literature (& and |
can actually be spelled as "AND" and "OR" or some other symbol).
And there for individual bits they use & just like everybody normally
uses * and they use | just like everybody normally uses +.
The rules for * and + are very similar to those for & and |.
0 * 0 = 0 = 0 & 0
0 * 1 = 0 = 0 & 1
1 * 0 = 0 = 1 & 0
1 * 1 = 1 = 1 & 1
0 + 0 = 0 = 0 | 0
0 + 1 = 1 = 0 | 1
1 + 0 = 1 = 1 | 0
1 + 1 = non-zero = 1 | 1
a * b = b * a
a + b = b + a
a & b = b & a
a | b = b | a
(a * b) * c = a * (b * c)
(a + b) + c = a + (b + c)
(a & b) & c = a & (b & c)
(a | b) | c = a | (b | c)
(a + b) * c = (a * c) + (b * c)
(a | b) & c = (a & c) | (b & c)
So, it looks pretty natural to me to treat & and | similar to * and +.

Alex

Re: Order of transformation of values

<sue9qp$o35$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1795&group=comp.lang.misc#1795

  copy link   Newsgroups: comp.lang.misc
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc@freeuk.com (Bart)
Newsgroups: comp.lang.misc
Subject: Re: Order of transformation of values
Date: Mon, 14 Feb 2022 19:16:40 +0000
Organization: A noiseless patient Spider
Lines: 72
Message-ID: <sue9qp$o35$1@dont-email.me>
References: <smb189$qs8$1@dont-email.me>
<927ca42a-3c1f-4508-94c3-db8594598aa0n@googlegroups.com>
<suc9te$8sr$1@dont-email.me>
<4cf1e65d-a2a0-478b-b4ea-265755fa38b2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 14 Feb 2022 19:16:41 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4744014386d56013812bebf9afd11750";
logging-data="24677"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/cSEpiQTxzKJwcabIlOFWyyGH28wuHBSk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.0
Cancel-Lock: sha1:Ypy00cJ8Crxix1DnD1AHCaKrfCI=
In-Reply-To: <4cf1e65d-a2a0-478b-b4ea-265755fa38b2n@googlegroups.com>
 by: Bart - Mon, 14 Feb 2022 19:16 UTC

On 14/02/2022 02:01, Alexei A. Frounze wrote:
> On Sunday, February 13, 2022 at 5:05:51 PM UTC-8, Bart wrote:
>> On 13/02/2022 22:22, Alexei A. Frounze wrote:
>>> If I were to redo C's "operator precedence", which is flawed for historical
>>> reasons (B and/or BCPL to Blame, handy!), I'd reduce the total number of
>>> the levels in the binary operators (fewer to remember):
>>> 1. *, /, %, <<, >>, &
>>> (* and << kinda multiply, / and >> kinda divide, % and & kinda compute modulo,
>>> * and & also kinda multiply)
>>> 2. +, -, |, ^
>>> (+, | and ^ kinda add)
>>> 3. ==, !=, <=, <, >, >=
>>> (no good reason to separate these)
>>> 4. &&
>>> 5. ||
>>> 6. ?:
>>> I'd likely make =, +=, ++ and such non-expressions and drop the comma
>>> operator altogether.
>>> I'd probably rework ?: as well (make it left-associative), not entirely sure.
>> This is not far off the groupings I use. For the operators listed (and
>> using those same names), they are:
>>
>> 1 * / % << >> (shifts scale the value)
>>
>> 2 + - & | ^ (all bitwise ops are the same; they don't scale, so
>> they belong neither above or below, so why not here)
>
> If I view bitwise operator operands as just collections of individual/
> independent bits, then separating & from | (and ^) lets me use the
> same precedence as often used in computer literature (& and |
> can actually be spelled as "AND" and "OR" or some other symbol).
> And there for individual bits they use & just like everybody normally
> uses * and they use | just like everybody normally uses +.
> The rules for * and + are very similar to those for & and |.
> 0 * 0 = 0 = 0 & 0
> 0 * 1 = 0 = 0 & 1
> 1 * 0 = 0 = 1 & 0
> 1 * 1 = 1 = 1 & 1
> 0 + 0 = 0 = 0 | 0
> 0 + 1 = 1 = 0 | 1
> 1 + 0 = 1 = 1 | 0
> 1 + 1 = non-zero = 1 | 1
> a * b = b * a
> a + b = b + a
> a & b = b & a
> a | b = b | a
> (a * b) * c = a * (b * c)
> (a + b) + c = a + (b + c)
> (a & b) & c = a & (b & c)
> (a | b) | c = a | (b | c)
> (a + b) * c = (a * c) + (b * c)
> (a | b) & c = (a & c) | (b & c)
> So, it looks pretty natural to me to treat & and | similar to * and +.

I think of it in ALU terms. If you have an N-bit API, and give it inputs
A and B, with output C, then for bitwise operations, each output bit
C[i] corresponds only to A[i] & B[i] etc, independently of all the other
bits.

There is no shifting or scaling.

With add and subtract, these would also apply, so that A[i]+B[i] gives a
result C[i] which is either 0 or 1; but there is now also a carry or
borrow bit that can propagate through the result. I don't consider that
shifting (except that doing A+A is equivalent to A << 1).

In any case, they are close enough to be treated as the same precedence
(also I can't think of a reason for & | ^ to be higher or lower).

Multiplication and division can be implemented with adds, subtracts and
shifts, while << and >> are pure shifts. So they clearly belong in the
same group. (A<<B is also just A*(2**B))

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor