Just some quick thoughts. It's well past my bedtime so I'm sorry if this
comes off as curt or snapping, it's not intended as such. I think this
is an interesting idea and a problem that a couple of contrib libraries
have had to hack around and/or reinvent.
Please squash all three patches for review. It's easier to read one diff
than three put together mentally. You would almost certainly get asked
to so do if these patches were on JIRA, and I did a squash myself to
read these changes.
https://github.com/arrdem/clojure/commit/37958a5
The gitignore changes almost certainly won't be accepted.
I note garbage whitespace in INumber.java, whitespace changes in
Numbers.java. The Core team doesn't have an official whitespace policy,
but it gets my goat at least.
How does this compare to the existing implementation? I slapped the
following naive benchmark together which suggests that these patches
generate a (small) slowdown compared to 1.6.0. 100,019ms compared to
99,346ms on my not especially beefy laptop. 1.7.0 top of tree clocks in
at 98,353ms. So a net slowdown. I would be surprised if the Core team
will take these changes at a slowdown. I may be wrong since it's small
and brings a win for library authors, but breaking even or coming out
ahead would probably help these changes along. Benchmarking with
primitive math?
<code>
(time
(let [ctors [int long float double bigint],
;; FIXME: primitive ops?
ops [+ +' - -' * *' /],
rng (range 1 1000)]
;; FIXME: use futures returning ((ctor, ctor, op), time-msg)
(doseq [lhs ctors, rhs ctors,
lval rng, rval rng,
op ops]
(let [l (lhs lval)
r (rhs rval)]
(op l r)))))
</code>
Can this completely replace say algo.generic? I think it does, at least
for the clojure.algo.generic.arithmetic namespace. It'd be interesting
to see interval arithmetic, arithmetic with error terms, composite
numbers, vectors or some other numeric type implemented as a proof of
concept.
It would also be interesting to here Mikera sound off on the
implications for numeric-tower, algo.generic and core.matrix all of
which AFAIK tackle the same problem (extending core's numbers).
Documentation? I know that there's not a whole lot officially "public"
in clojure.lang, but if this is a candidate for extension with custom
numeric types then it should probably have docs to assist therewith
rather than expecting users to reverse engineer clojure.core/+ or some
other function.
Will be interested to see where this thread goes,
Reid