Hacker News new | past | comments | ask | show | jobs | submit login

You can implement it entirely in the parser if you can avoid name capture - it may or may not be implemented entirely as a tweak to the parser in practice, but it's fundamentally a syntactic thing.

Your discussion of types here is all wrong - it's true that C treats booleans as if they were integers, but Python does, too:

    >>> (3 > 4) < 2
    True
    >>> 3 > 4 < 2
    False
    >>> 3 > (4 < 2)
    True
It has nothing to do with types.



I think the comparison is more readable as (here with the >>> of the python shell):

    >>> 0 < x < 1
as opposed to

    >>> 1 > x > 0
Following the number line and placing x there is nicer IMHO. Other than that, very nice trick.


In terms of coding style, I agree with you that following the number line is usually going to be clearest. I think there might be some situations where descending is better than ascending, but certainly both are radically better than what I did above (low > high < lower).

As an example for what I was specifically trying to show here, though, that doesn't let me distinguish things quite as clearly.

I believe that (a < x < b) gives the same value as at least one of (a < x) and (x < b) for any value of x.

    x < a:
        a < x gives false
        a < x < b gives false

    a < x < b:
        everything gives true

    b < x:
        x < b gives false
        a < x < b gives false
So there's no way to get both of the parenthesized versions to disagree with the unparenthesized version in a single example.


Oh fun. That is not a nice associativity weirdness to have to deal with.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: