4 ms·
0 < -1 < 2 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, synt
by skrebbel 7y ago
0 < -1 < 2
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 :-)
- benatkin 7y agoIt's a big ask, to have a binary operator and ternary operator that use the same symbol.
- Doxin 7y agoIt's honestly some fairly trivial AST-twiddling to support that feature. the compiler can simply detect cases where the left-hand-side of a comparison is /also/ a comparison and change the AST to make it two comparisons combined with an AND statement. 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.
- benatkin 7y agoI know, but it isn't a very useful feature, so why bother?
- ghettoimp 7y agoWorks beautifully in Common Lisp. Of course, it is not mainstream. ? (< 0 1 2) T ? (< 0 -1 2) NIL
- deleted 7y ago[deleted]
- jdminhbg 7y agoIn Clojure: user=> (< 0 1 2) true And user=> (< 0 -1 2) false
- xeeeeeeeeeeenu 7y agoPerl 5.32 will support this syntax: https://perldoc.pl/5.31.10/perldelta#Chained-comparisons-capability https://perldoc.pl/5.31.10/perldelta#Chained-comparisons-cap...