<!-- 
RSS generated by JIRA (4.4#649-r158309) at Sat May 25 17:44:17 CDT 2013

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary add field=key&field=summary to the URL of your request.
For example:
http://dev.clojure.org/jira/si/jira.issueviews:issue-xml/CLJS-204/CLJS-204.xml?field=key&field=summary
-->
<rss version="0.92" >
<channel>
    <title>Clojure JIRA</title>
    <link>http://dev.clojure.org/jira</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>4.4</version>
        <build-number>649</build-number>
        <build-date>25-07-2011</build-date>
    </build-info>

<item>
            <title>[CLJS-204] Bug in sort</title>
                <link>http://dev.clojure.org/jira/browse/CLJS-204</link>
                <project id="10040" key="CLJS">ClojureScript</project>
                        <description>&lt;p&gt;The sort function (and thus sort-by) do not seem to be behaving as they would in normal Clojure. For example, in my ClojureScript REPL I have:&lt;/p&gt;

&lt;p&gt;ClojureScript:cljs.user&amp;gt; (def values (list &lt;span class=&quot;error&quot;&gt;&amp;#91;-11 10&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-8 12&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-15 -4&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;4 5&amp;#93;&lt;/span&gt;))&lt;br/&gt;
(&lt;span class=&quot;error&quot;&gt;&amp;#91;-11 10&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-8 12&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-15 -4&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;4 5&amp;#93;&lt;/span&gt;)&lt;br/&gt;
ClojureScript:cljs.user&amp;gt; (sort values)&lt;br/&gt;
(&lt;span class=&quot;error&quot;&gt;&amp;#91;-11 10&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-15 -4&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-8 12&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;4 5&amp;#93;&lt;/span&gt;)&lt;/p&gt;

&lt;p&gt;But in the Clojure REPL, you get what one would expect:&lt;br/&gt;
user=&amp;gt; (def values (list &lt;span class=&quot;error&quot;&gt;&amp;#91;-11 10&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-8 12&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-15 -4&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;4 5&amp;#93;&lt;/span&gt;))&lt;br/&gt;
#&apos;setback.core/values&lt;br/&gt;
user=&amp;gt; (sort values)&lt;br/&gt;
(&lt;span class=&quot;error&quot;&gt;&amp;#91;-15 -4&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-11 10&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;-8 12&amp;#93;&lt;/span&gt; &lt;span class=&quot;error&quot;&gt;&amp;#91;4 5&amp;#93;&lt;/span&gt;)&lt;/p&gt;

&lt;p&gt;I have only noticed this bug for sorting vectors, since in Clojure vectors are sorted position by position.&lt;/p&gt;</description>
                <environment>Mac OS X, recently cloned ClojureScript repository</environment>
            <key id="15363">CLJS-204</key>
            <summary>Bug in sort</summary>
                <type id="1" iconUrl="http://dev.clojure.org/jira/images/icons/bug.gif">Defect</type>
                                <priority id="2" iconUrl="http://dev.clojure.org/jira/images/icons/priority_critical.gif">Critical</priority>
                    <status id="5" iconUrl="http://dev.clojure.org/jira/images/icons/status_resolved.gif">Resolved</status>
                    <resolution id="1">Completed</resolution>
                                <assignee username="neotyk">Hubert Iwaniuk</assignee>
                                <reporter username="snilan">Sean Nilan</reporter>
                        <labels>
                        <label>clojure</label>
                    </labels>
                <created>Wed, 25 Apr 2012 08:15:16 -0500</created>
                <updated>Fri, 18 May 2012 19:28:13 -0500</updated>
                    <resolved>Fri, 18 May 2012 19:28:13 -0500</resolved>
                                                                    <due></due>
                    <votes>0</votes>
                        <watches>2</watches>
                        <comments>
                    <comment id="28267" author="snilan" created="Wed, 25 Apr 2012 08:52:05 -0500"  >&lt;p&gt;The bug is actually in the compare function, which uses the google.array.defaultCompare as the compare function for vectors. A simple patch such as below could fix the problem:&lt;/p&gt;


&lt;p&gt;(defn vector-compare&lt;br/&gt;
    &lt;span class=&quot;error&quot;&gt;&amp;#91;v1 v2&amp;#93;&lt;/span&gt;&lt;br/&gt;
    (cond&lt;br/&gt;
      (and (empty? v1) (empty? v2))&lt;br/&gt;
        0&lt;br/&gt;
      (empty? v1)&lt;br/&gt;
        -1&lt;br/&gt;
      (empty? v2)&lt;br/&gt;
        1&lt;br/&gt;
      :default&lt;br/&gt;
      (let [cmp (apply compare (map first &lt;span class=&quot;error&quot;&gt;&amp;#91;v1 v2&amp;#93;&lt;/span&gt;))]&lt;br/&gt;
        (if (zero? cmp)&lt;br/&gt;
          (vector-compare (rest v1) (rest v2))&lt;br/&gt;
          cmp))))&lt;/p&gt;


&lt;p&gt;(defn compare&lt;br/&gt;
  &quot;Comparator. Returns a negative number, zero, or a positive number&lt;br/&gt;
  when x is logically &apos;less than&apos;, &apos;equal to&apos;, or &apos;greater than&apos;&lt;br/&gt;
  y. Uses google.array.defaultCompare for objects of the same type&lt;br/&gt;
  and special-cases nil to be less than any other object.&quot;&lt;br/&gt;
  &lt;span class=&quot;error&quot;&gt;&amp;#91;x y&amp;#93;&lt;/span&gt;&lt;br/&gt;
  (cond&lt;br/&gt;
    (and (vector? x) (vector? y)) (vector-compare x y)&lt;br/&gt;
    (identical? (type x) (type y)) (garray/defaultCompare x y)&lt;br/&gt;
    (nil? x) -1&lt;br/&gt;
    (nil? y) 1&lt;br/&gt;
    :else (throw (js/Error. &quot;compare on non-nil objects of different types&quot;))))&lt;/p&gt;</comment>
                    <comment id="28268" author="dnolen" created="Wed, 25 Apr 2012 08:54:24 -0500"  >&lt;p&gt;Thanks. We need a IComparable protocol.&lt;/p&gt;</comment>
                    <comment id="28503" author="neotyk" created="Wed, 16 May 2012 03:11:00 -0500"  >&lt;p&gt;IComparable protocol, implementations and tests.&lt;/p&gt;</comment>
                    <comment id="28504" author="dnolen" created="Wed, 16 May 2012 08:15:01 -0500"  >&lt;p&gt;Can we squash the commits here? Thanks!&lt;/p&gt;</comment>
                    <comment id="28505" author="neotyk" created="Wed, 16 May 2012 08:30:21 -0500"  >&lt;p&gt;Commits squashed.&lt;/p&gt;</comment>
                    <comment id="28506" author="dnolen" created="Wed, 16 May 2012 11:31:02 -0500"  >&lt;p&gt;Why do we need to extend IComparable to strings, arrays, boolean, and number?&lt;/p&gt;</comment>
                    <comment id="28511" author="neotyk" created="Thu, 17 May 2012 14:17:45 -0500"  >&lt;p&gt;booleans - are supported in clj&lt;br/&gt;
number - special case in clj, not sure if it brings any speed increase, will test with jsperf&lt;br/&gt;
arrays - are supported in clj&lt;br/&gt;
strings - to support symbols and keywords&lt;/p&gt;</comment>
                    <comment id="28520" author="neotyk" created="Fri, 18 May 2012 07:46:35 -0500"  >&lt;p&gt;Simplified version, just to solve comparing vectors.&lt;/p&gt;</comment>
                    <comment id="28528" author="dnolen" created="Fri, 18 May 2012 19:28:13 -0500"  >&lt;p&gt;fixed, &lt;a href=&quot;http://github.com/clojure/clojurescript/commit/43ff1c4adea322e6edc1d368ff128f2ad47406a5&quot;&gt;http://github.com/clojure/clojurescript/commit/43ff1c4adea322e6edc1d368ff128f2ad47406a5&lt;/a&gt;&lt;/p&gt;</comment>
                </comments>
                    <attachments>
                    <attachment id="11227" name="CLJS-204-IComparable.patch" size="4550" author="neotyk" created="Fri, 18 May 2012 07:46:35 -0500" />
                </attachments>
            <subtasks>
        </subtasks>
                <customfields>
                                                                                            <customfield id="customfield_10010" key="com.pyxis.greenhopper.jira:gh-global-rank">
                <customfieldname>Global Rank</customfieldname>
                <customfieldvalues>
                    
                </customfieldvalues>
            </customfield>
                                            <customfield id="customfield_10000" key="com.atlassian.jira.plugin.system.customfieldtypes:select">
                <customfieldname>Patch</customfieldname>
                <customfieldvalues>
                        <customfieldvalue key="10002">Code and Test</customfieldvalue>

                </customfieldvalues>
            </customfield>
                                                                                        </customfields>
    </item>
</channel>
</rss>