Honestly, Python's way is the only sane way to parse this. This is how a human who never programmed before with some knowledge of math would understand it.
Everyone's else mind is just corrupted by broken legacy languages.
>>> a=16
>>> a*a is a*a
True
>>> a=17
>>> a*a is a*a
False
“is”, “==“, and “=“ are all very different and none of them match their mathematical equivalents very well.The objects for small integers are built-in and static, but 17^2 is too big, and so new integer objects are created when the expressions are evaluated. "is" checks if two expressions represent the same object in memory. "==" checks for equality of values.
if a == 2 or 3:
do stuff
because that's how they would write it in math. Does that mean Python is broken and should support that construct as well? # See stackoverflow/highlyupvoted/wtf/does/python/do/here
# This is the same as (a < b) < c.
x = a < b < c
whih is not clearer, not easier to parse and not faster to read and harder to maintain (leads to rot easily when variable names change) than the non-ambiguous other choice. user=> (< 1 2 3)
trueI have programmed python for about 20 years, and I still do stupid mistakes. I grooked all the r6rs scheme syntax in 20 minutes, except for (do ...) which somehow never sticks. It is also rarely used.
I have tried to evangelize scheme enough to know some people just don't like it, but for me it instantly clicked.
The problem I think is that not= returns true as long as any elements are non-equal, which means it is not analogous to +. I can't speak for clojure, but this is in line with all equality predicates in scheme, negated or not. A predicate that checked if any neighbours are not equal would in true scheme spirit probably be called not-any-neighbour-equal? :)
Parentheses take precedence.
The first symbol is the operator (add, subtract, sum, multiply, etc.).
Everything else is operated on from left to right.
(+ 2 5 7)
2+5+7
It's also not a Clojure thing. It applies to all Lisps or related like Scheme.
In APLish languages, it's (a<(b<c)).
julia> 2<3<4
truePython comes second for source code niceness, allowing you to compare numbers to booleans is common and shouldn't be.
In most languages, like C++, a < b < c ends up comparing a boolean to an integer. This should be a type error, but isn't.