When building a custom comparator function in CLJS I encountered some IMO strange behaviour:
When using the > (or similar) function with two strings directly in the REPL I get an :invalid-arithmetic warning and nil is returned (somewhat similar to CLJ that raises an exception). When I do the same inside a function it will return a boolean with no warning at all (CLJ raises an exception)
CLJS:
clj꞉user꞉> (> "A" "Z")
nil
; ------ WARNING - :invalid-arithmetic -------------------------------------------
; Resource: <eval>:1:1
cljs.core/>, all arguments must be numbers, got [string string] instead
--------------------------------------------------------------------------------
clj꞉user꞉> ((fn [x y] (> x y)) "A" "Z")
false
CLJ:
user=> (> "A" "Z")
Execution error (ClassCastException) at user/eval3 (REPL:1).
class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')
user=> ((fn [x y] (> x y)) "A" "Z")
Execution error (ClassCastException) at user/eval5$fn (REPL:1).
class java.lang.String cannot be cast to class java.lang.Number (java.lang.String and java.lang.Number are in module java.base of loader 'bootstrap')
Can anyone explain what is going on?
Thanks,
Julian