Inverse parentheses

21 points by edk-


owl

Did you know that Python’s grammar has braces? You just don’t type them. The tokeniser keeps track of the indentation level and inserts special tokens when it changes.

Reminded me of that Fortran story:

An ingenious idea used in the first FORTRAN compiler was to surround binary operators with peculiar-looking parentheses:

+ and - were replaced by )))+((( and )))-(((

* and / were replaced by ))*(( and ))/((

** was replaced by )**(

and then an extra ((( at the left and ))) at the right were tacked on. The resulting formula is properly parenthesized, believe it or not. For example, if we consider "(X + Y) + W/Z," we obtain

((((X))) + (((Y)))) + (((W))/((Z))).

This is admittedly highly redundant, but extra parentheses need not affect the resulting machine language code. After the above replacements are made, a parenthesis-level method can be applied to the resulting formulas.

roryokane

I wondered if the examples would be easier to read if the syntax was also inverted, to avoid seeing () with two different meanings. After replacing () with )(, I’m not sure that the examples are any easier to read:

> )1 + 2( * 3
1 + 2 * 3
> 1 + )2 * 3(
(1 + 2) * 3
> ))1 * 2(( + )3 * 4(
1 * ((2 + 3) * 4)

The (( + ) in the last example looks unbalanced. I’m just too used to seeing parentheses that face each other as grouped.

I do think the examples are easier to read after replacing () with []:

> [1 + 2] * 3
1 + 2 * 3
> 1 + [2 * 3]
(1 + 2) * 3
> [[1 * 2]] + [3 * 4]
1 * ((2 + 3) * 4)
hush

the 1 + (2 * 3) example looks really strange to me because it groups the 2 with the excluded expression. If the intent is to exclude phrases, such that this would evaluate to (1 + 2) * 3, doesn't it make more sense to just put parentheses around ( * 3), so that it is isolated from the rest? It feels more intuitive that 1 + 2 ( * 3) would evaluate the 1 + 2 first.