News for hackers. Stuff that matters.
Re:Many programming languages have infix expressions, but ge... by jamesbritt on Sunday January 31, 2010 @07:35PM (#1091428)
The author, in an adorable little attempt to wear big-boy pants[0], seems not to know that '<' is a message passed to a receiver. You can even redefine it if you like.

Better pseudo code would be

    1.lt(2).lt(3)
In fact, this is correct (albeit ungainly) ruby code

    1.<(2)  # true
and so

    1.<(2).<(3) # Say wha ... ?
makes no sense.

[0]: Yes, a cheap shot.

Re:Many programming languages have infix expressions, but ge... by mikedouglas on Sunday January 31, 2010 @07:52PM (#1091459)
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.
Re:Many programming languages have infix expressions, but ge... by psygnisfive on Sunday January 31, 2010 @08:46PM (#1091553)
Unfortunately 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.
Re:Many programming languages have infix expressions, but ge... by xenophanes on Sunday January 31, 2010 @08:50PM (#1091562)
1 < 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.

Re:Many programming languages have infix expressions, but ge... by ubernostrum on Monday February 01, 2010 @12:22AM (#1091851)
The 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.
Re:Many programming languages have infix expressions, but ge... by brettnak on Monday February 01, 2010 @03:35AM (#1092040)
> 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.