On Thu, Oct 7, 2010 at 4:21 AM, Stuart Halloway
<stuart.hallo...@gmail.com> wrote:
> Which version of Clojure are you running?
>
> The most likely cause of this problem is having a mix of numeric types (e.g. 
> longs and ints) as keys/key lookups in a hash map. This is broken as required 
> (sigh) by Java collections.

I think this advice may be a bit misleading.   In Clojure 1.1 and 1.2,
it's extremely hard to get a mixture of numeric types in a hash map as
long as you're not using Java interop, because in Clojure 1.1 and 1.2,
there is one canonical representation for every Clojure number
(numbers auto-reduce).  Since the sample code posted uses no Java
interop, and all the numbers are either literals or produced by
Clojure arithmetic, I don't see at a glance how it's possible for this
problem to be caused by a mix of numeric types.

>
> Clojure 1.3 improves the story by having Clojure's collections defy the rules 
> of Java, unless you are calling them through the Java interfaces in an 
> interop scenario.
>

Clojure 1.3 also complicates the story since a number can now be
represented in more than one way.  For Project Euler problems
especially, it will now be important for users to understand the
details of how integer arithmetic works and know when to use the
"prime" operators to avoid overflow errors.  It is now much more
likely to end up with a mixture of numeric types in, say, a hash map,
even if you code entirely in Clojure with no Java interop.  There is
new code that hopefully makes the mixture of numeric types work
properly, but it is alpha code and may still contain bugs.  I find it
entirely plausible that the poster is using Clojure 1.3 and the
problem is caused by some of these new intricacies.

Either way, I agree that it would be very useful to know which version
of Clojure the original poster is using, since there have been major
changes to the way math works in Clojure 1.3 alpha.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to