Details

Type: Defect

Status: Open

Priority: Major

Resolution: Unresolved

Affects Version/s: None

Fix Version/s: None

Component/s: None

Labels:None

Patch:Code
Description
This ClojureScript change
https://github.com/clojure/clojurescript/commit/bcf60ce194e5292fbc5c4b2d89dfc5a7b886b94c
tracked this Clojure change
https://github.com/clojure/clojure/commit/20f67081b7654e44e960defb1e4e491c3a0c2c8b
A consequence is that int? is satisfied by goog.math.Integer which is not fixedprecision.
Also, it creates a situation where it is possible to have values that satisfy int? but don't satisfy integer? or number?. (Note that this also affects things like posint?.)
I'd propose two alternative approaches to fix this that we can debate:
Alternative A: Simply remove the goog.math items from int? and friends.
Alternative B: Have goog.math.Long values satisfy number?, integer?, and int? and have goog.math.Integer values satisfy number? and integer?.
In either case, the docstrings should be updated.
I'll attached two concrete patches for consideration / debate.
What should be the goal for the various numeric predicates in CLJS?
Is the goal to align with CLJ's meaning of these predicates? If so then:
number? true for typeofnumber or goog.math.Integer or goog.math.Long
integer? true for goog.math.isInt/Number.isInteger or goog.math.Integer or goog.math.Long
int? true for goog.math.isInt/Number.isInteger or goog.math.Long
Is the goal to align with some notion of platformprimitiveness? If so then:
number? true for typeofnumber or goog.math.Integer or goog.math.Long
integer? true for goog.math.isInt/Number.isInteger or goog.math.Integer or goog.math.Long
int? true for goog.math.isInt only
Is the goal to be a canIdoarithmeticwiththis type check? If so then:
number? true for typeofnumber only
integer? true for goog.math.isInt (or maybe even Number.isSafeInteger)
int? same as integer?
In Java/CLJ these three goals are much more aligned with one another. Any numberasidentifier can also be used for clj arithmetic (so the widest check, number?, can also be used for arithmetic checking), and int? corresponds exactly to the host's mostprimitive integer valuetypes (vs objecttype).
CLJS lacks a number tower so it's more interesting.
Right now in CLJS number? appears to be designed as a predicate to test for whether arithmetic is possible, so it only allows js typeof===number. integer? is also an arithmetic check, but wants a nonfractional number (interestingly, still allowing unsafe integers, i.e. outside Number.MAX_SAFE_INTEGER, where normal integer arithmetic doesn't workperhaps it should only allow safe integers). int? doesn't care about arithmetic, but it's still useful for seeing if a value could be a numeric identifier (e.g. a record id received via transit); but that's expressly not what CLJ's int? cares about.