On Tue, Apr 20, 2010 at 6:43 PM, jvshahid <[email protected]> wrote:
> Thanks Per,
>
> This definitely works
>
>> Try (loop [x (. 1 longValue)] (if (= 0 x) x (recur (- x (long 1))))).
>
> but from my understanding of clojure internals clojure.lang.Numbers
> should take care of that.
The Numbers class doesn't do any fancy dispatching for primitive
types. You can see there are direct static methods for the arithmetic
operations on primitive types like longs, floats, etc:
static public long add(long x, long y){
long ret = x + y;
if ((ret ^ x) < 0 && (ret ^ y) < 0)
return throwIntOverflow();
return ret;
}
Then there is a catch-all implementation for Object which double
dispatches on the dynamic types of the operands to determine the right
Ops implementation. It then delegates all the real work to that:
static public Number add(Object x, Object y){
return ops(x).combine(ops(y)).add((Number)x, (Number)y);
}
With the way primitive types are currently supported in the compiler,
if you wanted it to work the way you expect, you'd need to express the
complicated arithmetic tower and its grid of type conversions in a
static form accessible to the compiler. It seems like it would be a
good amount of work. You can file a feature request for it if you
want.
-Per
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en