Live data from Hacker News

Inverse Parentheses

kellett.im

51–60 of 67 posts

Re: Inverse Parentheses

#51

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…

well I'll be that guy... If you're going to disturb the normal way of righting expressions, RPN or prefix notation (AKA Polish Notation) could be a better option. Both don't need parenthesis because they don't need precedence/priority rules - which are obviously a disadvantage of the infix notation.

The HP 48 famously took the bet of going against the mainstream notation. I wonder to what extent this is one of those "accidents of history".

RPN moreover simplifies parsing, as shown by the Forth language.

Prefix notation, as used by for instance Lisp, doesn't actually need parenthesis either; Lisp uses them because it allows extensions over basic operators and more generally "variadic" operators and functions (e.g. (+ 1 2 3 4)). Without this "fancy" feature, prefix notation is unambiguous as well: / + 1 2 3. [1]

On a side note, Smalltalk is one of the few languages that said "duck it", and require explicit parenthesis instead - which is IMO, not an insane approach when you see that for languages with 17 levels of priority like C, you end up putting parenthesis anyway as soon as the expression is not trivial "just to be sure" (e.g. because it mixes boolean operators, arithmetic operators and relational operators as in a & 0xF [1] https://en.wikipedia.org/wiki/Polish_notation

Re: Inverse Parentheses

#52
Prompt: 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.

Re: Inverse Parentheses

#53

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…

well I'll be that guy... If you're going to disturb the normal way of righting expressions, RPN or prefix notation (AKA Polish Notation) could be a better option. Both don't need parenthesis because they don't need precedence/priority rules - which are obviously a disadvantage of the infix notation. The HP 48 famously took the bet of going against the mainstream notation. I wonder to what extent this is one of those…

The HP 48 followed a couple of decades of HP calculators using RPN (hardly famous, just an evolution). HP’s first calculator used RPN.

I recommend https://www.hpmuseum.org/ for more details.

Re: Inverse Parentheses

#54

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 defi…

APL uses a simple right to left order of evaluation :)

Re: Inverse Parentheses

#55

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.

Do you really like Lisp?

Re: Inverse Parentheses

#56

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…

llm generated comment

I am sure your comment is almost always wrong whenever you use it.

Re: Inverse Parentheses

#58
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 + 4

Re: Inverse Parentheses

#60
post #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…

I believe Peano dot notation works the other way ’round;

  A . B : C :. D
would be, as I understand it, equivalent to:

  ((A B) C) D
The “general principle” is that a larger number of dots indicates a larger subformula.¹

What if you need to nest parentheses? Then you use more dots. A double dot (:) is like a single dot, but stronger. For example, we write ((1 + 2) × 3) + 4 as 1 + 2 . × 3 : + 4, and the double dot isolates the entire 1 + 2 . × 3 expression into a single sub-formula to which the + 4 applies.²

A dot can be thought of as a pair of parentheses, “) (”, with implicit parentheses at the beginning and end as needed.

In general the “direction” rule for interpreting a formula ‘A.B’ will be to first indicate that the center dot “works both backwards and forwards” to give first ‘A).(B’, and then the opening and closing parentheses are added to yield ‘(A).(B)’. The extra set of pairs of parentheses is then reduced to the formula (A.B).³

So perhaps one way of thinking about it is that more dots indicates more separation.

¹ https://plato.stanford.edu/entries/pm-notation/dots.html

² https://blog.plover.com/math/PM.html

³ https://plato.stanford.edu/entries/pm-notation/dots.html

See also https://plato.stanford.edu/entries/pm-notation/index.html and https://muse.jhu.edu/article/904086.

Post reply on HN