r/ProgrammingLanguages • u/AsIAm 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.
View all comments
Show parent comment
3
u/guywithknife Jan 06 '26
That’s actually true. LSP would solve the main complaints I had about the editor.
I’m still wary of it, relying on editors to make something readable (and then displaying it otherwise) makes me wonder about the point of supporting the less readable way at all. Why not just add LSP code actions or support something like paredit to make editing simpler, and always display in the readable canonical form?
Besides in the age of LLM code assist, I wonder what the value of saving a few keystrokes really is (and anyway, as a touch typist, keystrokes was never the bottleneck in programming for me).
So while using an LSP to show the information does solve the immediate issue being discussed, I still wonder if you should perhaps take a step back and re-evaluate the value and purpose of the feature.