r/ProgrammingLanguages • New Kind of Paper • Jan 05 '26

Significant Inline Whitespace

I have a language that is strict left-to-right no-precedence, i.e. 1 + 2 * 3 is parsed as (1 + 2) * 3. On top of that I can use function names in place of operators and vice versa: 1 add 2 or +(1, 2). I enjoy this combo very much – it is very ergonomic.

One thing that bothers me a bit is that assignment is also "just a function", so when I have non-atomic right value, I have to enclose it in parens: a: 23 – fine, b: a + 1 – NOPE, it has to be b: (a + 1). So it got me thinking...

I already express "tightness" with an absent space between a and :, which could insert implicit parens – a: (...). Going one step further: a: 1+ b * c would be parsed as a:(1+(b*c)). Or going other way: a: 1 + b*c would be parsed same – a:(1+(b*c)).

In some cases it can be very helpful to shed parens: a:((b⊕c)+(d⊕e)) would become: a: b⊕c + d⊕e. It kinda makes sense.

Dijkstra in his EWD1300 has similar remark (even though he has it in different context): "Surround the operators with the lower binding power with more space than those with a higher binding power. E.g., p∧q ⇒ r ≡ p⇒(q⇒r) is safely readable without knowing that ∧ ⇒ ≡ is the order of decreasing binding power. [...]" (One funny thing is he prefers fn.x instead of fn(x) as he hates "invisible operators". I like his style.)

Anyway, do you know of any language that uses this kind of significant inline whitespace please? I would like to hear some downsides this approach might have. I know that people kinda do this visual grouping anyway to express intent, but it might be a bit more rigorous and enforced in the grammar.

P.S. If you like PEMDAS and precedence tables, we are not gonna be friends, sorry.

27 Upvotes

68 comments sorted by

View all comments

Show parent comment

10

u/dcpugalaxy Jan 05 '26

Modern mathematical notation is actually pretty new. If you go back to early modern era mathematical writing it is all like "add the first unknown quantity to the second unknown quantity and if the resulting quantity is greater in its value than the product of the two quantities produced in the last paragraph...".

The notation we have has evolved over time because it works well.

6

u/AsIAm New Kind of Paper Jan 05 '26

The notation evolved on the paper, and it allowed notation to be non-consistent & ambiguous. Computers changed that – programming languages require that expressions have single unambiguous meaning. APL (A Programming Language by Kenneth Iverson) wanted to be modern consistent and executable mathematical notation. It has so many genius decisions, yet so many flaws. It is really a language from 2066 invented in 1966.

2

u/SirKastic23 Jan 05 '26

Oh yeah that's true, my bad

centuries ago then, definitely before the computer and GPLs