by userbinator · 6y ago · 0 comments
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.
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? >>> 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. # 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)
trueParentheses 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.
I 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.
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.