Live data from Hacker News

Inverse Parentheses

kellett.im

41–50 of 67 posts

Re: Inverse Parentheses

#41
post #37

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…

If we actually (as the title seems to imply) invert the parentheses, then for your example we get 1+2)*(3 . Now all you need are the opening and closing parentheses at the start and end, and we're back to normal.

Yeah, that seems a much more robust formulation of the whole thing. Flip all parens and enclose the whole string in more parens.

Re: Inverse Parentheses

#42
post #17

Am I stupid if I don't get it? What is the intended end state? What does "ungroup operands" mean?

I think ungrouping make sense if you consider reverse parentheses as a syntactic construct added to the language, and not replacing the existing parentheses.

For instance, using "] e [" as the notation for reverse parentheses around expression e, the second line showing reverse parenthese simplification, third line showing the grouping after parsing, and the fourth line using postfix notation:

A + B * (C + D) * (E + F)

=> A + B * (C + D) * (E + F)

=> (A + (B * (C + D) * (E + F)))

=> A B C D + E F + * * +

A + ] B * (C + D) [ * (E + F)

=> A + B * C + D * (E + F)

=> ((A + (B * C)) + (D * (E + F)))

=> A B C * + D E F * + +

So what ungrouping would mean is to undo the grouping done by regular parentheses.

However, this is not what is proposed later in the article.

Possibilities include reversing the priority inside the reverse parentheses, or lowering the priority wrt the rest of the expression.

Re: Inverse Parentheses

#43
post #37

Earlier quoted context omitted.

If we actually (as the title seems to imply) invert the parentheses, then for your example we get 1+2)*(3 . Now all you need are the opening and closing parentheses at the start and end, and we're back to normal.

Yeah, that seems a much more robust formulation of the whole thing. Flip all parens and enclose the whole string in more parens.

that results in

    (1+2)*(3)  
which is (as GP notes), equivalent to "normal", ie what we do today:

    (1+2)*3  
Right?

Re: Inverse Parentheses

#44
post #6

I was hoping the parentheses themselves would be flipped. Like this: > 1 + )2 * 3( (1 + 2) * 3

Same. That said if you try to use that with ordinary parentheses usage it would get ambiguous as soon as you nest them

Wait, no. It makes no sense to use the same characters! An "inverted" opening parens is visually identical to a "normal" closing parens. IMHO the entire proposition is inane.

Re: Inverse Parentheses

#45
post #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 thin…

Clearly we need left-associative and right-associative inverse parentheses.

a & )b $ c) @ d would mean ((a & b) $ c) @ d.

a & (b $ c( @ d would mean a & (b $ (c @ d)).

Combining both, a & )b $ c( @ d would mean (a & b) $ (c @ d).

;)

Re: Inverse Parentheses

#46

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…

> There is another alternative, parenthesis.

Gerald Jay "Jerry" Sussman from Scheme and SICP fame (and others) would tell you there's also the prefix notation (but ofc only infix makes TFA valid: prefix or postfix makes it mostly moot). "3 x 4 x 7 x 19" only looks natural to us because we've been taught that notation as toddlers (well, ok, as young kids).

But "x 3 4 7 19" is just as valid (Minksy and having to understand someting in five different ways or you don't understand it etc.).

P.S: also your comment stinks of AI to me.

Re: Inverse Parentheses

#47
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.

Re: Inverse Parentheses

#48
post #37

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…

If we actually (as the title seems to imply) invert the parentheses, then for your example we get 1+2)*(3 . Now all you need are the opening and closing parentheses at the start and end, and we're back to normal.

Thank you. I thought I was going crazy reading the article which doesn’t connect open and close parenthesis :: higher and lower precedence :: indent and outdent :: +1 and -1 and just flip it around to get the opposing polarity.

A real Wesley Crusher moment.

Post reply on HN