News for hackers. Stuff that matters.
Re:Show HN: “Crafting Interpreters” chapter, control flow an... by pacaro on Monday June 26, 2017 @04:39PM (#14640173)
The author asks why && and || need different precedence (Unless I misunderstood).

This is because `a && (b || c)` has a different truth table than `(a && b) || c`

Re:Show HN: “Crafting Interpreters” chapter, control flow an... by rspeele on Monday June 26, 2017 @05:14PM (#14640441)
&& having higher precedence than || makes sense because && is boolean multiplication and || is boolean addition.
Re:Show HN: “Crafting Interpreters” chapter, control flow an... by DonaldPShimoda on Monday June 26, 2017 @11:06PM (#14642284)
This makes so much sense but I never thought of it this way before so explicitly. Neat!
Re:Show HN: “Crafting Interpreters” chapter, control flow an... by agumonkey on Tuesday June 27, 2017 @04:23AM (#14643368)
Has anyone ever found a link between boolean (F2) and "normal" base (F[n], or N) arithmetics ?
Re:Show HN: “Crafting Interpreters” chapter, control flow an... by oconnor0 on Monday June 26, 2017 @05:05PM (#14640360)
That doesn't explain why they would need a different precedence. `a + b - c` is not the same as `a - b + c` even through the precedence's of + and - are the same (in most syntaxes).
Re:Show HN: “Crafting Interpreters” chapter, control flow an... by pacaro on Tuesday June 27, 2017 @12:34AM (#14642604)
Granted, the intersection of precedence and associativity is a great source of confusion (and any number of annoying Facebook memes)

I'm not a formally trained mathematician, but one way to rationalize + and - having the same precedence, is to consider them as inverses of each other, so your two examples can be written as

a + -b + c

And

a + b + -c

At which point precedence and associativity no longer matter. The same can be done with multiplication and division