Numeric don't compare arrays correctly
Mike C. Fletcher
mcfletch at rogers.com
Sat Jun 7 05:36:28 CEST 2003
Alexander Schmolck wrote:
>>>``3 < 1 < 4`` (False in python, True in most other languages where it isn't a
>Well, it is only obvious because you (and I) are already used to a rather
Ah, but what I'm saying is that, if you see this construct:
a < b < c
then the only non-hackish interpretation is a is less than b which is
less than c, which is taken directly from mathematics. The hackish
(low-level, fiddly) intpretation says "what would the machine do" and
figures out that it's grouping the statements and basically producing
random data ;) .
>>Hopefully all those languages with these semantics issue a strong warning
>>during compilation (1/5 ;) ) that this statement does nothing useful and
>>should never be used in anything save obfuscated code contests :) .
> printf("Is 1 < 1 < 1 true? %d\n", 1 < 1 < 1);
> return 0;
>>gcc -Wall /tmp/ex.c
>Is the 1 < 1 < 1 true? 1
And here I was trying to protect the guilty ;) .
>I tend to agree, but in this case I'm not so sure. After all pythons
>conformance with the expected "common sense" behavior breaks down nastily for
Certainly bad rich-comparisons are a wart, but in the line of cutting it
off, I'd rather have an error raised (syntax error) for a < b < c than
have it work as a built-in random data generator :) . That is, the
(current) common sense behaviour is by far preferable to the
(randomising) behaviour of those unnamed languages, but really, who
needs either behaviour so much that the subtle errors it can introduce
are worth the risk?
Yes, the symetry with x == y == z is nice, but again, dropping that
construct entirely would be better than switching to (x == y) == z
semantics. I mean x == y and y == z isn't *that* much harder to type,
and neither is (x == y) & (y==z) if you want the element-wise stuff.
Explicit is better, ...yada, yada... refuse to guess :) .
Peace and love to all the stunted, warped and twisted languages :) ,
Mike C. Fletcher
Designer, VR Plumber, Coder
More information about the Python-list