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.
> Have you ever noticed that lots of programming languages let you use parentheses to group operands, but none use them to ungroup them?
Since this doesn't exist in practice, shouldn't the article author first explain what they mean by that?
Am I stupid if I don't get it? What is the intended end state? What does "ungroup operands" mean?
I was hoping the parentheses themselves would be flipped. Like this:
> 1 + )2 * 3(
(1 + 2) * 3
Echoing the sentiment that I'm not really sure what I'm meant to be looking at here. A motivating example at the start would have helped, I think.
Working with lisp quickly made me realize how over-rated operator precedence (or even the concept of "operators") is. All such effort and early grade-school hours spent on this arbitrary short-hand instead of treating the operations themselves as functions and embracing the divine order of (more) parens.
The real question is, why does Python even have parentheses? If semantic indent is superior to braces, it ought to beat parentheses, too. The following should yield 14:
a = 2 *
3 + 4Prompt: Suggest a topic for a short blog post that will nerd-snipe as many readers as possible while making no actual sense at all.
System: How about “Inverse Parentheses”? We can write the entire article without ever defining what it means. Nerds will be unable to resist.
Is it the same as flipping every parenthesis to the other side of the number it's adjacent to, and then adding enough parentheses at the start and end?
For example,
(1 + 2) * (3 + 4)
becomes 1) + (2 * 3) + (4
and then we add the missing parentheses and it becomes (1) + (2 * 3) + (4)
which seems to achieve a similar goal and is pretty unambiguous.The footnotes are top-tier ADHD. Particularly loved the footnote on a footnote, 10/10.
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.
The singular for parenthesis is paren.
I am in the middle of developing a parser for a new language with original representation vs. syntax issues to resolve.
Clearly, this was the worst possible time for me to come across this brain damaging essay.
I really can’t afford it! My mathematical heart can’t help taking symmetrical precedence control seriously. But my gut is experiencing an unpleasant form of vertigo.
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.
I think reading this let me experience the feeling a Bene Gesserit has when they hear about a preborn.
Parenthesis used to decrease precedence? Everything outside of the parenthesis will be done before what is in the parenthesis?
Where do stars live? Thats what I wonder.
Using Brave on MacOS, I cannot scroll the page to see the entire text. On Firefox, it scrolls fine.
I don't understand
Opened this excitedly, thinking I was going to get something related to S-expressions/Lisp, was disappointed...
Ha! I was expecting/wondering something about the semantics of )( parenthesis (which I have no idea what it could be, but... why not?)
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?
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 weakening. Have you tested it on non-arithmetic ops (logical/bitwise) or more complex expressions like ((()))?
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?
There is another alternative, parenthesis. Those mean "do the thing inside first" so (1+2)*3 changes the precedence and now you do 1+2 first, then *3
The post is asking: with parenthesis you can increase the precedence of operations. What if you could decrease it?
Let's use «» as another operand (the blog uses parenthesis, but that makes it really confusing) this operand means "do the thing inside last". So the expression 1+«2*3» means "do 1+ first, then 2*3.
The issue is...this doesn't make sense, what the blog is really saying is to reduce the precedence of operators. Think the expression 1+2«*»3 or 1+2(*)3 and now the rule is "the parenthesized operators have one precedence less" so 1+2(*)3=(1+2)*3