Live data from Hacker News

Inverse Parentheses

kellett.im

21–30 of 67 posts

Re: Inverse Parentheses

#21
Slightly unrelated:

Instead of ordinary brackets, one can also use the dot notation. I think it was used in Principia Mathematica or slightly later:

  (A (B (C D)))
would be

  A . B : C .: D
Essentially, the more dots you add, the stronger the grouping operator is binding. The precedence increases with the number of dots.

However, this is only a replacement for ordinary parentheses, not for these "reverse" ones discussed here. Maybe for reverse, one could use groups of little circles instead of dots: °, °°, °°°, etc.

Re: Inverse Parentheses

#22

The concept of "inverse parentheses" that unbundle operators is brilliant! The tokenizer hack (friendliness score by parenthesis depth, inspired by Python INDENT/DEDENT) + precedence climbing for infinite levels is elegant – parsing solved without convoluted recursive grammar. kellett I love the twist: reversing the friendly levels gives you a classic parser, and it opens up crazy experiments like whitespace weakenin…

It's not just brilliant, it's earth-shattering.

Re: Inverse Parentheses

#23

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

Thanks, this makes more sense, the blog post was written in a really confusing way.

Re: Inverse Parentheses

#24
Regarding the first two footnotes, I’m pretty sure that originally the singular form “parenthesis” just refers to the aside inserted (by use of brackets, like this) into a sentence. Because it sounds like a plural and because of the expression “in parenthesis”, people probably mistakenly applied the word to the pair of symbols, and when that became common, started using the real plural “parentheses”. This has staying power because it’s fancy and “brackets” is way overloaded, but historically it’s probably just wrong and especially nonsensical in math and programming, where we don’t use them to insert little sidenotes.

Re: Inverse Parentheses

#25

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

Thanks, writing it as 1+2(*)3 made it click for me.

Reminds me of the '$' operator in Haskell - it lowers the precedence of function application, basically being an opening parenthesis that's implicitly closed at the end of the line.

Re: Inverse Parentheses

#26

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

This seems to be the best guess so far. But then I am wondering, how is

    a (*) b + c
Parsed then? The precedence of '* is bumped down, but does that mean it has now strictly lower precedence of '+', or the same? In the first case the operation is parsed as

    a * (b + c)
In the second case, the "left to right" rule takes over and we get

    (a * b) + c
And what happens when there are more than 2 priority groups Taking C has an example, we have that '' has higher precedence than '+' which has higher precedence than '
    a + b * c 
Means

    (a + (b * c)) 
Now I could use the "decrease precedence" operator you proposed (possibly proposed by the author?) and write

    a + b (*) c 
Which then bumps down the precedence of '
' to... One level lower? Which means the same level of '+', or a level lower, i.e. a new precedence level between '+' and 'The more I think about this, the less sense it makes...

[1] https://en.cppreference.com/w/c/language/operator_precedence...

Re: Inverse Parentheses

#27

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

I don't think that's even well-defined if you have arbitrary infix operators with arbitrary precedence and arbitrary associativity (think Haskell). If $, & and @ are operators in that order of precedence, all right-associatve. Using your notation, what is:

  a & > @ d
If $ is reduced below & but above @ then it's the same as:

  ((a & b) $ c) @ d
If it's reduced below both & and @ then it becomes:

  (a & b) $ (c @ d)
I think conceptualizing parentheses as "increase priority" is fundamentally not the correct abstraction, it's school brain in a way. They are a way to specify an arbitrary tree of expressions, and in that sense they're complete.

Re: Inverse Parentheses

#28

Based on this comment ( https://news.ycombinator.com/item?id=46352389 ), I think I understood the missing first paragraph: If you have the expression 1+2*3 you have three elements with two operands. You need to choose a rule to pick one of them first. In mathematics, the rule is "*/ then +-" and then from left to right. This means that usually first you do 2*3, then 1+. But what if you do want to make 1+2 first? Ther…

Thanks indeed. Using a simple left-to-right evaluation is the most logical solution. You can reorder expressions to use less parentheses and make them easier to read. E.g.: Smalltalk :-). But this requires everyone un-learning their primary school maths of e.g. multiply-before-add, so it's not popular. Having hand-picked operator precedences complicates things further when you allow operator overloading and user defined operators. E.g. Swift has special keywords to specify precedence for these. Ick...

Re: Inverse Parentheses

#29
post #8

I'm all for terseness in blog writing, but I think the author forgot to add the content. I know nothing more than I did when I opened it.

And yet, this is the top entry on HN right now?! How does that happen??

Re: Inverse Parentheses

#30
The core idea: normally, parentheses strengthen grouping:

1 + (2 * 3) forces 2 * 3 to happen first.

Without them, operator precedence decides. The post asks a deliberately strange question:

What if parentheses did the opposite — instead of grouping things tighter, they made them bind less tightly?

Post reply on HN