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 06 '26
I think Ken made a few mistakes. 🫣
> APL is like a beautiful diamond - flawless, beautifully symmetrical. But you can't add anything to it. If you try to glue on another diamond, you don't get a bigger diamond. Lisp is like a ball of mud. Add more and it's still a ball of mud - it still looks like Lisp. -- Joel Moses
I am trying to position Fluent to be somewhere in between APL -- LISP spectrum. So far I like the balance I got. I can use very terse-looking expressions, while they are still context-free, i.e. parsed always the same – no matter what symbols mean. I can still enjoy higher-order functions (compose, flip, fork, combinators, etc.) and they are just a normal function calls. And you can make your own combinators – no need to wait for new version of the language that adds a single symbol.
I admit it is a weird mix. And I haven't even mentioned autodiff, reactive values, whole development environment, etc. Also a lot of stuff missing. :D