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
1
u/AsIAm New Kind of Paper Jan 05 '26
Yes, this is a great idea! Do you know of some editor, where it was perfectly done?
Fluent (the name of the language) strives to be somewhere in the middle of LISP <-> APL spectrum. You can do M-expr style e.g.
a(b, c(d, e))or go infix –b a (d c e), or use higher-order operators likecompose, hook, fork, flip, etc., while you can easily create ad-hoc operators, e.g.(∘): compose, (⑃):fork, (- ∘ ⑃(Σ, ÷, #))([1,2,6])will result in negative mean of[1,2,6], so-3.Strict left-to-right & no-precedence is huge enabler.