The coercion rules were a big surprise to me when I first started to work in JS. Sometimes codes were obvious but the underlying interpretation is a surprise call.
The coercion rules were a big surprise to me when I first started to work in JS. Sometimes codes were obvious but the underlying interpretation is a surprise call.
To be fair, is there any mainstream language other than Python where that expression makes sense at all?
And even Python had to make explicit, syntactical support for it, and IMO it's a pretty non-obvious language hack. I mean, there's an invisible AND in there, that's pretty astonishing to me at least :-)
That said I find comparison chaining rather confusing and unexpected so I make a point of avoiding its use. Typing it out as two comparisons hardly saves any effort in any case.
? (< 0 1 2)
T
? (< 0 -1 2)
NIL
user=> (< 0 1 2)
true
And user=> (< 0 -1 2)
falseJavascript is convenient for many use cases, but it definitely violates POLA on many levels, in many situations!
In what language (other than a RPN based language like Lisp) would this expect to return something meaningful?