3 ms·
The underlying mechanism doesn't matter if it's wrong. Those familiar with the mathematical notation would think: 1. '1 < 2 < 3' parses to '(1 < 2) and (
by mikedouglas 17y ago
The underlying mechanism doesn't matter if it's wrong.
Those familiar with the mathematical notation would think:
1. '1 < 2 < 3' parses to '(1 < 2) and (2 < 3)'.
2. '3 - 4 - 5' parses to '(3 - 4) - 5'.
3. '3 ^ 4 ^ 5' parses to '3 ^ (4 ^ 5)'.
Ruby's convention is clever, but ultimately wrong, and this is one of the cases.
- psygnisfive 17y agoUnfortunately Ruby is not wrong. Ruby is simply being strictly correct from a logic point of view, where < is R^2 -> {T, F}, as opposed to being strictly correct from a math-notation point of view, where < is treated syncategorematically. Neither is correct, sans qualification; given that Ruby is not aimed at mathematicians, it's not unsurprising to find that it's not going to go through the extra parsing effort to use math notation.
- xenophanes 17y ago1 < 2 < 3 DOES evaluate to (1 < 2) < 3 And 1 < 2 evaluates to true. What else would it evaluate to? That leaves (true < 3) Which fails. This isn't a mistake by ruby. When you chain methods you have to think about what they return. And the issue here isn't associativity.
- deleted 17y ago[deleted]
- ubernostrum 17y agoThe comment you're replying to was not asserting that Ruby fails to follow its own rules, but rather arguing with the rules Ruby follows; other languages have made an exception to their normal rules for this case, and apparently some people feel it would be better for Ruby to do the same.
- brettnak 17y ago> 3. '3 ^ 4 ^ 5' parses to '3 ^ (4 ^ 5)'. I actually think that a trained mathematician would have no idea what to do with 3 ^ 4 ^ 5. It's a completely ambiguous statement and has no proper mathematical parsing.