<p>On the subject of associativity when all operators have equal precendence, Ken Iverson writes in <a href="https://www.jsoftware.com/papers/EvalOrder.htm" rel="nofollow noreferrer">Conventions Governing Order of Evaluation</a> that</p>
<blockquote>
<p>The reasons for choosing a right-to-left instead of a left-to-right convention are:</p>
<ol>
<li>The usual mathematical convention of placing a monadic function to the left of its argument leads to a right-to-left execution for monadic functions; for example, <code>F G x ≡ F (G x)</code> .</li>
<li>The notation <code>F/z</code> for reduction (by any dyadic function <code>F</code>) tends to require fewer parentheses with a right-to-left convention. For example, expressions such as <code>+/(x×y)</code> or <code>+/(u/x)</code> tend to occur more frequently than <code>(+/x)×y</code> and <code>(+/u)/x</code> .</li>
<li>An expression evaluated from right to left is the easiest to read from left to right. For example, the expression<pre>
a+x×b+x×c+x×d+x×e+x×f
</pre>(for the efficient evaluation of a polynomial) is read as a plus the entire expression following, or as a plus x times the following expression, or as a plus x times b plus the following expression, and so on.</li>
<li>In the definition<pre>
F/x ≡ x1 F x2 F x3 F ... F x⍴x
</pre>the right-to-left convention leads to a more useful definition for nonassociative functions F than does the left-to-right convention. For example, <code>-/x</code> denotes the alternating sum of the components of <code>x</code> , whereas in a left-to-right convention it would denote the first component minus the sum of the remaining components. Thus if d is the vector of decimal digits representing the number <code>n</code> , then the value of the expression <code>0=9|+/d</code> determines the divisibility of <code>n</code> by <code>9</code> ; in the right-to-left convention, the similar expression <code>0=11|-/d</code> determines divisibility by <code>11</code> .</li>
</ol>
</blockquote>
<p><strong>What would be the reasons for choosing a left-to-right convention?</strong></p>

<syntax><precedence>
Why choose a left-to-right convention?
CC BY-SA 4.0
2023-05-17T12:55:35.293Z
Most choices regarding language conventions comes down to "it's what users are now used to".
chrisaycock
CC BY-SA 4.0
2023-05-17T12:57:39.487Z
@chrisaycock Sure, but that doesn't mean no reasons exist that are disconnected from what people are used to. In this paper, Iverson broke with the traditional precedence he had adhered to in his previous writings.
Adám
CC BY-SA 4.0
2023-05-17T12:58:02.957Z
Smalltalk uses left-to-right evaluation for everything, even when you wouldn’t think the operators have equal precedence (e.g. `1 + 2 * 3` is 9). Would an explanation of that be relevant here?
Bbrk24
CC BY-SA 4.0
2023-05-17T13:01:25.437Z
@Bbrk24 Smalltalk's *reasons* for that would be relevant.
Adám
<h1>Consistency with pure OO</h1>
<p>In Smalltalk, everything is a method (even operators), and all methods that take more arguments than just <code>self</code> use infix syntax. Using a simple left-to-right rule solidifies this consistency, and avoids having to implement precedence for regular methods.</p>
<p>Obviously, this has the drawback of running counter to mathematical convention, when <code>1 + 2 * 3</code> is 9 rather than 7.</p>

CC BY-SA 4.0
2023-05-17T13:03:22.027Z
2023-05-17T13:03:22.027Z
Bbrk24
CC BY-SA 4.0
2023-05-17T13:04:56.107Z
So, one-argument methods/operators are postfix?
Adám
CC BY-SA 4.0
2023-05-17T13:06:13.373Z
Correct, assuming you’re counting `self` in the argument count.
Bbrk24
CC BY-SA 4.0
2023-05-17T13:11:14.450Z
OK, but then having one-argument methods/operators be prefix would be equally consistent with right-to-left. What reason is there to go suffix, then?
Adám
CC BY-SA 4.0
2023-05-17T13:12:31.660Z
Many OO langs treat the self/this argument separately — it’s no different than C++ doing `foo.bar()` instead of `bar(foo)`.
Bbrk24
CC BY-SA 4.0
2023-05-17T13:13:51.743Z
Sure, but isn't `()bar.foo` equally sensible?
Adám
CC BY-SA 4.0
2023-05-17T13:14:15.687Z
To answer more explicitly: postfix notation means that you always have `self methodName args`, no matter how many args there are (even 0).
Bbrk24
CC BY-SA 4.0
2023-05-17T13:15:32.153Z
And prefix notation means that you always have `(args) methodName self` no matter how many args there are (even 0).
Adám
CC BY-SA 4.0
2023-05-17T13:20:20.673Z
Method declarations omit the ‘self’ parameter and thus always start with the method name. You could make the argument that the other way it would always _end_ with the method name, but at that point it likely comes down to either ease of implementation or what programmers are used to.
Bbrk24
<h1>Easier writing</h1>
<p>In my experience writing APL programs, I constantly have to press the left arrow key to type in the next part of my program. A left-to-right evaluation would would effectively reverse that, allowing for a more natural flow of program writing. Note that this would apply more to symbolic languages like APL and golfing languages, instead of conventional C derivatives.</p>

CC BY-SA 4.0
2023-05-17T14:49:51.943Z
2023-05-17T14:49:51.943Z
Seggan
# Why choose a left-to-right convention?
Posted by: username_0 on 2023-05-17
On the subject of associativity when all operators have equal precendence, Ken Iverson writes in Conventions Governing Order of Evaluation that

The reasons for choosing a right-to-left instead of a left-to-right convention are:

The usual mathematical convention of placing a monadic function to the left of its argument leads to a right-to-left execution for monadic functions; for example, F G x ≡ F (G x) .
The notation F/z for reduction (by any dyadic function F) tends to require fewer parentheses with a right-to-left convention. For example, expressions such as +/(x×y) or +/(u/x) tend to occur more frequently than (+/x)×y and (+/u)/x .
An expression evaluated from right to left is the easiest to read from left to right. For example, the expression
a+x×b+x×c+x×d+x×e+x×f
(for the efficient evaluation of a polynomial) is read as a plus the entire expression following, or as a plus x times the following expression, or as a plus x times b plus the following expression, and so on.
In the definition
F/x ≡ x1 F x2 F x3 F ... F x⍴x
the right-to-left convention leads to a more useful definition for nonassociative functions F than does the left-to-right convention. For example, -/x denotes the alternating sum of the components of x , whereas in a left-to-right convention it would denote the first component minus the sum of the remaining components. Thus if d is the vector of decimal digits representing the number n , then the value of the expression 0=9|+/d determines the divisibility of n by 9 ; in the right-to-left convention, the similar expression 0=11|-/d determines divisibility by 11 .


What would be the reasons for choosing a left-to-right convention?
**Tags:** syntax precedence
> **Comments:**
> **username_1**: Most choices regarding language conventions comes down to "it's what users are now used to".  
> **username_0**: @chrisaycock Sure, but that doesn't mean no reasons exist that are disconnected from what people are used to. In this paper, Iverson broke with the traditional precedence he had adhered to in his previous writings.  
> **username_2**: Smalltalk uses left-to-right evaluation for everything, even when you wouldn’t think the operators have equal precedence (e.g. `1 + 2 * 3` is 9). Would an explanation of that be relevant here?  
> **username_0**: @Bbrk24 Smalltalk's *reasons* for that would be relevant.  
---
## 2 answers
### Answer by username_2 on 2023-05-17. Score: 5
# Consistency with pure OO

In Smalltalk, everything is a method (even operators), and all methods that take more arguments than just `self` use infix syntax. Using a simple left-to-right rule solidifies this consistency, and avoids having to implement precedence for regular methods.

Obviously, this has the drawback of running counter to mathematical convention, when `1 + 2 * 3` is 9 rather than 7.
> **Comments:**
> **username_0** (2023-05-17): So, one-argument methods/operators are postfix?  
> **username_2** (2023-05-17): Correct, assuming you’re counting `self` in the argument count.  
> **username_0** (2023-05-17): OK, but then having one-argument methods/operators be prefix would be equally consistent with right-to-left. What reason is there to go suffix, then?  
> **username_2** (2023-05-17): Many OO langs treat the self/this argument separately — it’s no different than C++ doing `foo.bar()` instead of `bar(foo)`.  
> **username_0** (2023-05-17): Sure, but isn't `()bar.foo` equally sensible?  
> **username_2** (2023-05-17): To answer more explicitly: postfix notation means that you always have `self methodName args`, no matter how many args there are (even 0).  
> **username_0** (2023-05-17): And prefix notation means that you always have `(args) methodName self` no matter how many args there are (even 0).  
> **username_2** (2023-05-17): Method declarations omit the ‘self’ parameter and thus always start with the method name. You could make the argument that the other way it would always _end_ with the method name, but at that point it likely comes down to either ease of implementation or what programmers are used to.  
---
### Answer by username_3 on 2023-05-17. Score: 4
# Easier writing

In my experience writing APL programs, I constantly have to press the left arrow key to type in the next part of my program. A left-to-right evaluation would would effectively reverse that, allowing for a more natural flow of program writing. Note that this would apply more to symbolic languages like APL and golfing languages, instead of conventional C derivatives.
---
