Hi all,

When creating a sorted set, the function sorted-set-by
cannot be called without at least one element, despite
the elements being optional.

Chouser on irc.freenode.net #clojure suggested this is a bug,  because:

20:26 < chouser> leafw: sorted-set-by allows for an empty list of initial
                 values, but passes that on to PersistentTreeSet/create as
                 null, but create doesn't check for null it just blindly calls
                 .length on it.


An example:


; This works:

(reduce
    (fn [s b]
      (conj s b))
    (sorted-set-by
      #(int (- (%1 :med) (%2 :med)))
      {:med Double/MAX_VALUE})
    [{:med 4} {:med 1} {:med 10}])

; Output:
#{{:med 1} {:med 4} {:med 10} {:med 1.7976931348623157E308}}


; But this doesn't work:

(reduce
    (fn [s b]
      (conj s b))
    (sorted-set-by
      #(int (- (%1 :med) (%2 :med))))
    [{:med 4} {:med 1} {:med 10}])

; Output:

Caused by: java.lang.NullPointerException
        at clojure.lang.PersistentTreeSet.create(PersistentTreeSet.java:32)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:90)
        at clojure.lang.Reflector.invokeStaticMethod(Reflector.java:202)
        at clojure.core$sorted_set_by__4242.doInvoke(core.clj:291)
        at clojure.lang.RestFn.invoke(RestFn.java:415)
        at user$eval__1103.invoke(NO_SOURCE_FILE:5)
        at clojure.lang.Compiler.eval(Compiler.java:4623)

-- 
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