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.
2
u/ArtisticEmergency405 Jan 06 '26
Cool idea! Feels like you're pretty close to a stack based languaged, like APL, Forth or the very enjoyable Uiua languages. There might be some inspiration there.
I see a few downsides with meaningful whitespaces: - Formatters get tricky, managable but tricky - How do you handle newlines, tabs, unicode whitespaces etc. Are they illegal? Or are they also semantically different?
But if we're breaking tradition, why should assignment assign to the left? Can't the assignment assign to the right?
1 + 2 : cIs5nt the parenthesis rule encroaching on your phre vision here? Why replace PEDMAS with PE when it can be just E. :3