Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
sorted-set-by fails when given no values
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Albert Cardona  
View profile  
 More options Nov 12 2009, 2:42 pm
From: Albert Cardona <sapri...@gmail.com>
Date: Thu, 12 Nov 2009 14:42:30 -0500
Local: Thurs, Nov 12 2009 2:42 pm
Subject: sorted-set-by fails when given no values
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:3 9)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImp l.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 must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Timothy Pratley  
View profile  
 More options Nov 12 2009, 5:59 pm
From: Timothy Pratley <timothyprat...@gmail.com>
Date: Thu, 12 Nov 2009 14:59:51 -0800 (PST)
Local: Thurs, Nov 12 2009 5:59 pm
Subject: Re: sorted-set-by fails when given no values

On Nov 13, 6:42 am, Albert Cardona <sapri...@gmail.com> wrote:

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

I'll create a patch to address, Rich I take it you'll accept a ticket
for this?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »