Re: Debugging a custom reader literal for a sorted-set

2013-08-09 Thread Jozef Wagner
This ticket may be related, http://dev.clojure.org/jira/browse/CLJ-1093 On Friday, August 9, 2013 12:08:06 AM UTC+2, Jozef Wagner wrote: It may be a bug somewhere in a Compiler. I've lost track at https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L6624 after

Debugging a custom reader literal for a sorted-set

2013-08-08 Thread David James
I am having trouble with an implementation of a custom reader literal called #sorted-set. Please see my short code first: https://github.com/xpe/sorted-map-literal Why does this work correctly: (to-sorted-map '(1 2 3 4)) #sorted-map (1 2 3 4) ; correct While this does not? #sorted-map (1 2 3 4

Re: Debugging a custom reader literal for a sorted-set

2013-08-08 Thread Jozef Wagner
, 2013 7:29:16 PM UTC+2, David James wrote: I am having trouble with an implementation of a custom reader literal called #sorted-set. Please see my short code first: https://github.com/xpe/sorted-map-literal Why does this work correctly: (to-sorted-map '(1 2 3 4)) #sorted-map (1 2 3 4

Re: Debugging a custom reader literal for a sorted-set

2013-08-08 Thread David James
That's a good point about: user= eval (to-sorted-map '(1 2 3 4))) {1 2, 3 4} But this should work, right? user= (assoc #sorted-map (:a 1 :b 2) :c 3) {:c 3, :a 1, :b 2} ; incorrect -- -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this

Re: Debugging a custom reader literal for a sorted-set

2013-08-08 Thread Jozef Wagner
It seems there is something else in data reader which causes this change. user= (class '#foo/sm (1 2 3 4)) clojure.lang.PersistentArrayMap user= (class (read-string #foo/sm (1 2 3 4))) clojure.lang.PersistentTreeMap It's quite puzzling. In both cases the evaluation does not take place, but

Re: Debugging a custom reader literal for a sorted-set

2013-08-08 Thread David James
I'd really appreciate if others could take a look. I wonder if it may be a Clojure reader bug. On Thu, Aug 8, 2013 at 3:55 PM, Jozef Wagner jozef.wag...@gmail.com wrote: It seems there is something else in data reader which causes this change. user= (class '#foo/sm (1 2 3 4))

Re: Debugging a custom reader literal for a sorted-set

2013-08-08 Thread Jozef Wagner
It may be a bug somewhere in a Compiler. I've lost track at https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compiler.java#L6624 after debugging this: user (def x `(quote ~(list 1 (clojure.lang.PersistentTreeMap/create (seq [1 2 3 4]) #'user/x user x (quote (1

sorted-set-by with custom comparator frauds equality

2013-07-25 Thread gixxi
Hi all, please consider the following record definition (defrecord RDistance [node dist visited]) as well as an instance and a tree set with a custom comparator ordering content first by :visited and after that by :dist (def d (RDistance. foo 1 0)) (def tree (sorted-set-by (comparator (juxt

distinction of defrecord instances in sorted-set-by does not work

2013-07-25 Thread gixxi
tree (sorted-set-by (comparator (juxt :visited :dist)) d)) I expect conj d again to the set would change the set, but doing so in the repl results in the set containing two equal elements user= (conj tree d) #{#user.RDistance{:node foo, :dist 1, :visited 0} #user.RDistance{:node foo, :dist 1

Re: sorted-set-by with custom comparator frauds equality

2013-07-25 Thread Meikel Brandmeyer (kotarak)
Hi, you are using comparator incorrectly. The function you pass there should return true, when x is to the left of y when called as (f x y). See the following example. user= (defrecord Foo [a b]) user.Foo ; Wrong usage: your example (The new element is always smaller!) user= (- (sorted-set

Re: distinction of defrecord instances in sorted-set-by does not work

2013-07-25 Thread Timo Mihaljov
d (RDistance. foo 1 0)) (def tree (sorted-set-by (comparator (juxt :visited :dist)) d)) I expect conj d again to the set would change the set, but doing so in the repl results in the set containing two equal elements user= (conj tree d) #{#user.RDistance{:node foo, :dist 1, :visited 0

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-25 Thread mnicky
a) (hash b)) (and (== (hash a) (hash b)) (not= a b) (or (contains? @m [a b]) (and (not (contains? @m [b a])) (swap! m conj [a b])) (defn sorted-set-po [po keys] (apply

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread mnicky
Thanks for the explanations! So is there a way to build a set or map that has sorting property independent from the element lookup? On Friday, March 16, 2012 2:03:15 AM UTC+1, Alan Malloy wrote: And this is exactly as it should be. The sorted set has no way to compare items other than

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Philip Potter
: Thanks for the explanations! So is there a way to build a set or map that has sorting property independent from the element lookup? On Friday, March 16, 2012 2:03:15 AM UTC+1, Alan Malloy wrote: And this is exactly as it should be. The sorted set has no way to compare items other than by your

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Cedric Greevey
presentation, by using a sort function that outputs a seq. (Inefficient if the sort will then be performed often for a given set.) Option 3: Implement your own sorted set type that handles sort-order collisions by having plain sets as equality buckets, using deftype, gen-class, or Java. Option 4

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-24 Thread Cedric Greevey
]) (and (not (contains? @m [b a])) (swap! m conj [a b])) (defn sorted-set-po [po keys] (apply sorted-set-by (po-to po) keys)) Input: a partial order (may be true for a b, true for b a, or false for both). Output: a sorted-set that uses a total order built

'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread mnicky
It seems that when using the sorted set with my own comparator (sorted-set-by), the lookup via 'contains?' function is based only on the part of the items that participate in the ordering: (contains? (sorted-set [1 :a] [2 :b]) [2 :c]) ;= false (contains? (sorted-set-by #( (%1 0) (%2 0)) [1

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Stuart Campbell
/master/src/jvm/clojure/lang/PersistentTreeMap.java#L285is responsible for this behaviour. Regards, Stuart On 13 March 2012 05:20, mnicky markus.mas...@gmail.com wrote: It seems that when using the sorted set with my own comparator (sorted-set-by), the lookup via 'contains?' function is based

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Mark Engelberg
It's not a problem with Clojure, it's also how Java behaves. For sorted-sets to work properly, your comparator *must* satisfy the trichotomy property of orderings. Consider a comparison predicate less?. The trichotomy property states that for all x,y, exactly one of the following hold: (less? x

Re: 'contains?' on 'sorted-set-by' based on the comparator only? (possible bug?)

2012-03-15 Thread Alan Malloy
And this is exactly as it should be. The sorted set has no way to compare items other than by your comparator. If it just arbitrarily decided to use = instead of checking that (zero? (compare x y)) it would not be using your comparator. Note also that the behavior of contains? is consistent

Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
Hi, How can I efficiently pick a random element from a sorted-set? If I try rand-nth I get this: user= (rand-nth (sorted-set 1 2 3)) java.lang.UnsupportedOperationException: nth not supported on this type: PersistentTreeSet (NO_SOURCE_FILE:0) I can get this expression to work if I naively apply

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Michael Gardner
On Sep 26, 2011, at 8:12 AM, Paul Richards wrote: How can I efficiently pick a random element from a sorted-set? If your sorted set is densely packed (if most possible values do appear in the set), then you could just pick a random value, see if it's in the set, and repeat until you find

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Benny Tsai
The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large sets is probably because nth is O(n) on sequences. nth is much much faster on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2 3))) and see if that works for your application. -- You received

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Jeremy Heiler
On Mon, Sep 26, 2011 at 9:12 AM, Paul Richards paul.richa...@gmail.com wrote: Hi, How can I efficiently pick a random element from a sorted-set? If I try rand-nth I get this: user= (rand-nth (sorted-set 1 2 3)) java.lang.UnsupportedOperationException: nth not supported on this type

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 2:12 pm, Paul Richards paul.richa...@gmail.com wrote: Hi, How can I efficiently pick a random element from a sorted-set? I've come up with a bit of a hack, which relies on me not caring about non-uniform distributions. If I create a custom comparator with a random backdoor, I can

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 6:13 pm, Jeremy Heiler jeremyhei...@gmail.com wrote: On Mon, Sep 26, 2011 at 9:12 AM, Paul Richards paul.richa...@gmail.com wrote: Hi, How can I efficiently pick a random element from a sorted-set? If I try rand-nth I get this: user= (rand-nth (sorted-set 1 2 3

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Paul Richards
On Sep 26, 6:04 pm, Benny Tsai benny.t...@gmail.com wrote: The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large sets is probably because nth is O(n) on sequences.  nth is much much faster on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2 3

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Benny Tsai
On Monday, September 26, 2011 2:58:59 PM UTC-6, Paul Richards wrote: This will replace an O(n) call to nth with an O(n) call to copy into a vector, so still leaving me with O(n). Oops, right :) If you're getting random elements out of the same sorted set multiple times, then it might

Re: Randomly select an element from a sorted-set (rand-nth (sorted-set ..))

2011-09-26 Thread Alan Malloy
On Sep 26, 2:12 pm, Paul Richards paul.richa...@gmail.com wrote: On Sep 26, 2:12 pm, Paul Richards paul.richa...@gmail.com wrote: Hi, How can I efficiently pick a random element from a sorted-set? I've come up with a bit of a hack, which relies on me not caring about non-uniform

sorted-set

2011-08-06 Thread Oded Badt
Trying to migrate some of my code from clojure and javascript to ClojureScript and I'm missing 'sorted-set' Does anyone know if is is one of those parts of the library that has just not yet been migrated? Or will not at all be migrated? Or maybe I'm getting something wrong and its usage

Re: sorted-set

2011-08-06 Thread Stuart Halloway
Trying to migrate some of my code from clojure and javascript to ClojureScript and I'm missing 'sorted-set' Does anyone know if is is one of those parts of the library that has just not yet been migrated? Or will not at all be migrated? Or maybe I'm getting something wrong and its usage

first element after an element in the sorted-set?

2011-05-24 Thread Sunil S Nandihalli
Hello everybody, is there a function to find the first element after an element in the sorted-set? (first-element-after 3 (sorted-set 1 2 3 4 5 6)) should return 4? thanks, Sunil. -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group

Re: first element after an element in the sorted-set?

2011-05-24 Thread Michael Wood
On 24 May 2011 08:07, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, is there a function to find the first element after an element in the sorted-set? (first-element-after 3 (sorted-set 1 2 3 4 5 6)) should return 4? How about this?: (first (drop-while (partial = 3

Re: first element after an element in the sorted-set?

2011-05-24 Thread Sunil S Nandihalli
after an element in the sorted-set? (first-element-after 3 (sorted-set 1 2 3 4 5 6)) should return 4? How about this?: (first (drop-while (partial = 3) (sorted-set 1 2 3 4 5 6))) -- Michael Wood esiot...@gmail.com -- You received this message because you are subscribed to the Google

Re: first element after an element in the sorted-set?

2011-05-24 Thread Sunil S Nandihalli
, 2011 at 11:45 AM, Michael Wood esiot...@gmail.com wrote: On 24 May 2011 08:07, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, is there a function to find the first element after an element in the sorted-set? (first-element-after 3 (sorted-set 1 2 3 4 5 6)) should

Aw: Re: first element after an element in the sorted-set?

2011-05-24 Thread Meikel Brandmeyer
Hi, maybe subseq to the rescue? user= (first (subseq (sorted-set 1 2 3 4 5 6) 3)) 4 I'm not sure about the perfomance, but I'd think it's fast? Sincerely Meikel -- You received this message because you are subscribed to the Google Groups Clojure group. To post to this group, send email

Re: Re: first element after an element in the sorted-set?

2011-05-24 Thread Sunil S Nandihalli
thanks Meikel.. what you suggested might be it.. Sunil. On Tue, May 24, 2011 at 1:48 PM, Meikel Brandmeyer m...@kotka.de wrote: Hi, maybe subseq to the rescue? user= (first (subseq (sorted-set 1 2 3 4 5 6) 3)) 4 I'm not sure about the perfomance, but I'd think it's fast? Sincerely

Re: first element after an element in the sorted-set?

2011-05-24 Thread Alan Malloy
Yes, subseq is fast. On May 24, 1:18 am, Meikel Brandmeyer m...@kotka.de wrote: Hi, maybe subseq to the rescue? user= (first (subseq (sorted-set 1 2 3 4 5 6) 3)) 4 I'm not sure about the perfomance, but I'd think it's fast? Sincerely Meikel -- You received this message because you

Re: Re: first element after an element in the sorted-set?

2011-05-24 Thread Chouser
On Tue, May 24, 2011 at 4:18 AM, Meikel Brandmeyer m...@kotka.de wrote: Hi, maybe subseq to the rescue? user= (first (subseq (sorted-set 1 2 3 4 5 6) 3)) 4 I'm not sure about the perfomance, but I'd think it's fast? Yes, this is right. Note you can also walk the other direction using

Re: implementing nth for sorted-set and sorted-map

2010-12-03 Thread Ken Wesson
On Fri, Dec 3, 2010 at 2:27 AM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Right now I am just seq ing it before using nth Sunil. The real oddity here is that nth doesn't seem to call seq on its argument. It probably should (for non-vector arguments). -- You received this message

implementing nth for sorted-set and sorted-map

2010-12-02 Thread Sunil S Nandihalli
Hello everybody, I am thinking it would be nice to have nth work for sorted-set and sorted-maps .. IMHO it makes at the least sense for sorted-set if not both .. is there a reason why this is not implemented already? Thanks, Sunil. -- You received this message because you are subscribed

Re: implementing nth for sorted-set and sorted-map

2010-12-02 Thread Sunil S Nandihalli
Right now I am just seq ing it before using nth Sunil. On Fri, Dec 3, 2010 at 12:55 PM, Sunil S Nandihalli sunil.nandiha...@gmail.com wrote: Hello everybody, I am thinking it would be nice to have nth work for sorted-set and sorted-maps .. IMHO it makes at the least sense for sorted-set

Why is there a transient for a set, but not for a sorted-set

2010-07-08 Thread Moritz Ulrich
Why does (transient #{}) works, but transient (sorted-set []) fails with an exception: clojure.lang.PersistentTreeSet cannot be cast to clojure.lang.IEditableCollection [Thrown class java.lang.ClassCastException] -- Moritz Ulrich Programmer, Student, Almost normal Guy http://www.google.com

Re: Why is there a transient for a set, but not for a sorted-set

2010-07-08 Thread Sean Devlin
a transient hash set, and converting to a persistent sorted set from the persistent hash set. On Jul 8, 7:25 am, Moritz Ulrich ulrich.mor...@googlemail.com wrote: Why does (transient #{}) works, but transient (sorted-set []) fails with an exception: clojure.lang.PersistentTreeSet cannot be cast

sorted-set-by drops elements

2010-04-16 Thread Razvan
Hi, Is this the intended behavior? (sorted-set-by (constantly 0) 1 2 3 4) returns #{1}. I would expect the set to contain all the elements, and the comparator to only affect sort order. Razvan -- You received this message because you are subscribed to the Google Groups Clojure group. To post

Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
Here's the source for sorted-set-by: (defn sorted-set-by Returns a new sorted set with supplied keys, using the supplied comparator. ([comparator keys] (clojure.lang.PersistentTreeSet/create comparator keys))) This is because your comparator is saying that everything is equal

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
It doesn't seem confusing to me. You are taking complete control of the set's local notion of ordering and equality. This is what I'd expect. Here's an example. First, a handy little function from Haskell: (defn on [key f] #(apply f (map key %))) Then: user (sorted-set-by (on :id compare

Re: sorted-set-by drops elements

2010-04-16 Thread Razvan
Why should sorting be related to the primary key? You should be able to sort on any attribute. If you wanted to sort a set of people by age would it make sense to only retain one person of each age? Sort order and identity should be orthogonal. Besides, if you need a collection based on primary

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
Maybe the example was poorly picked but the point stands: if you're asking for a sorted set based on a comparator, you should expect duplicate elements as dictated by comparator to be eliminated. If you wanted to sort a set of people by age, you wouldn't use a sorted set but a sorted sequence

Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
I think the fns you're interested in are sort and sort-by, not sorted- set-by. I know you might not like it, but there is a convention in JavaLand that a comparator value of 0 is identical in a sorted collection. This causes orthogonal concepts of order identity to be entwined. Sean On Apr 16

Re: sorted-set-by drops elements

2010-04-16 Thread Sean Devlin
CORRECTION, DON'T SHOOT!! I should have order value, not order identity. On Apr 16, 1:01 pm, Sean Devlin francoisdev...@gmail.com wrote: I think the fns you're interested in are sort and sort-by, not sorted- set-by. I know you might not like it, but there is a convention in JavaLand

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 12:01 AM, Sean Devlin francoisdev...@gmail.com wrote: I know you might not like it, but there is a convention in JavaLand that a comparator value of 0 is identical in a sorted collection. It's not a Java convention. It's intrinsic to the business of sorting. For sorting

Re: sorted-set-by drops elements

2010-04-16 Thread ataggart
The problem is you're unnecessarily conflating the value by which to base a sort (x and y in your example) with the elements of the set. Equality and ordinality are not the same thing. It should be perfectly reasonable to hand someone a set of unique objects sorted by some non-unique attribute of

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
Equality and ordinality are not the same thing.  It should be perfectly reasonable to hand someone a set of unique objects sorted by some non-unique attribute of the elements of the set. Sure, it's perfectly reasonable but it implies a different data structure. It sounds like you want a data

Re: sorted-set-by drops elements

2010-04-16 Thread Per Vognsen
On Sat, Apr 17, 2010 at 1:05 AM, Per Vognsen per.vogn...@gmail.com wrote: You can only do slow linear-time lookups by traversing the tree's nodes exhaustively. Correction: You do not have to do a linear search on the whole tree but only on the subset of the tree for which the comparator returns

Re: sorted-set-by drops elements

2010-04-16 Thread Chris Perkins
On Apr 16, 8:25 am, Razvan gigi.clan...@gmail.com wrote: Hi, Is this the intended behavior? (sorted-set-by (constantly 0) 1 2 3 4) returns #{1}. I would expect the set to contain all the elements, and the comparator to only affect sort order. I expected the same thing at first

sorted-set-by fails when given no values

2009-11-12 Thread Albert Cardona
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

Re: sorted-set-by fails when given no values

2009-11-12 Thread Timothy Pratley
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

Re: Why not sorted-set-by?

2009-03-25 Thread hoeck
Hi hjlee, there is already a filed issue and a patch from Timothy Pratley which adds sorted-set-by to clojure: http://code.google.com/p/clojure/issues/detail?id=76colspec=ID%20Type%20Status%20Priority%20Reporter%20Owner%20Summary But its priority is set tow low. erik

Re: Why not sorted-set-by?

2009-03-25 Thread Chouser
On Wed, Mar 25, 2009 at 7:21 AM, hoeck i_am_wea...@kittymail.com wrote: there is already a filed issue and a patch from Timothy Pratley which adds sorted-set-by to clojure: http://code.google.com/p/clojure/issues/detail?id=76colspec=ID%20Type%20Status%20Priority%20Reporter%20Owner%20Summary

Why not sorted-set-by?

2009-03-24 Thread hjlee
Hi, all. I'm experimenting clojure. Some code, I needed something like sorted-set-by, but no such thing. So i used sorted-map-by ignoring value part. Is it deliberate for some reason? Or just not there? --~--~-~--~~~---~--~~ You received this message because you

Why not sorted-set-by?

2009-03-24 Thread hjlee
Hi all. I'm experimenting cljoure. some code, i needed something like sorted-set-by. but, no such thing, so I emulated that using sorted-map-by. Is it deliberate for some reason? or just not there? --~--~-~--~~~---~--~~ You received this message because you

Why not sorted-set-by?

2009-03-24 Thread hjlee
Hi, all. I'm experimenting clojure. Some code, I needed something like sorted-set-by, but no such thing. So i used sorted-map-by ignoring value part. Is it deliberate for some reason? Or just not there? --~--~-~--~~~---~--~~ You received this message because you

I'm experimenting clojure - sorted-set-by?

2009-03-24 Thread hjlee
Hi, all. I don't know why my previous posts ignored. spam filtering? so i changed title. I'm experimenting clojure. Some code, I needed something like sorted-set-by, but no such thing. So i used sorted-map-by ignoring value part. Is it deliberate for some reason? Or just

Re: I'm experimenting clojure - sorted-set-by?

2009-03-24 Thread Frantisek Sodomka
Hello! Yes, you are right, sorted-set-by is missing. Good news is - it is on the way :-) See issue 76: http://code.google.com/p/clojure/issues/detail?id=76 Frantisek On Mar 24, 5:35 am, hjlee hj.d@gmail.com wrote: Hi, all. I don't know why my previous posts ignored. spam filtering? so

Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Frantisek Sodomka
sorted-set works for vectors, but doesn't work for lists, maps and sets: user= (sorted-set [1 4]) #{[1 4]} user= (sorted-set [1 4] [1 4]) #{[1 4]} user= (sorted-set [4 1] [1 4]) #{[1 4] [4 1]} user= (sorted-set '(1 4)) #{(1 4)} user= (sorted-set '(1 4) '(1 4)) java.lang.ClassCastException

Re: Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Vincent Foley
I'm pretty sure that sorted-set works only with values that are instances of a class that implements Comparable. user= (instance? Comparable []) true user= (instance? Comparable {}) false user= (instance? Comparable ()) false user= On Feb 20, 2:21 pm, Frantisek Sodomka fsodo...@gmail.com wrote

Re: Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Frantisek Sodomka
It looks that it is more complicated than that: user= (sorted-set () ()) #{()} user= (sorted-set {} {}) #{{}} user= (sorted-set #{} #{}) #{#{}} Frantisek On 20 Ún, 20:33, Vincent Foley vfo...@gmail.com wrote: I'm pretty sure that sorted-set works only with values that are instances of a class

Re: Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Jason Wolfe
It probably does an identical? call on a pair before calling compare, for efficiency. In other words, it may work on non- comparable types, but only when passed n instances of the exact same object: user (sorted-set '(1) '(1)) ; Exception user (let [x '(1)] (sorted-set x x)) #{(1

Re: Possible bug in sorted-set, question about comparisons

2009-02-20 Thread Frantisek Sodomka
object: user (sorted-set '(1) '(1)) ; Exception user (let [x '(1)] (sorted-set x x)) #{(1)} This is almost certainly not documented behavior and should not be relied upon. Cheers, Jason On Feb 20, 11:42 am, Frantisek Sodomka fsodo...@gmail.com wrote: It looks that it is more

Re: Bugs in set and sorted-set (?)

2009-02-15 Thread Rich Hickey
, but it would still beg the question as to where to place the bounds, if other than exact match. For instance: (count #{(hash-set 1) (sorted-set 1)}) === ??? they are both sets but not the same exact type. Note that things are no different in Java, which also has polymorphic collections

Re: Bugs in set and sorted-set (?)

2009-02-15 Thread Frantisek Sodomka
It is making more sense now. One other interesting thing that surprised me is: There is not a total ordering across types. See discussion: http://groups.google.com/group/clojure/browse_frm/thread/710848919c68981f/51ede18b2fd7ab96?lnk=gstq=sorted-set#51ede18b2fd7ab96 Therefore things like (sort

Re: Bugs in set and sorted-set (?)

2009-02-14 Thread Frantisek Sodomka
2]]) #{[] [1 2]} user= (set [[] [1 2] 1]) #{[] 1 [1 2]} user= (set [[] [1 2] ()]) #{[] [1 2]} user= (set [() [] [1 2]]) #{() [1 2]} What data types is sorted-set supposed to work on? When used with different data types, it errors out:http://clojure.org/data_structures user= (doc sorted

Re: Bugs in set and sorted-set (?)

2009-02-14 Thread Chouser
On Sat, Feb 14, 2009 at 7:19 PM, Stephen C. Gilardi squee...@mac.com wrote: set is a hash set. It will never contain two items with equal hashes. I don't think that's quite right. I don't think it matters in this case, but hash values aren't guaranteed unique. A hash-map can have two keys

Re: sorted-set-by?

2009-02-11 Thread Timothy Pratley
Added a patch as issue 76 http://code.google.com/p/clojure/issues/detail?id=76 user= (sorted-set-by #( (:hat %1) (:hat %2)) {:hat 2} {:hat 3} {:hat 1}) #{{:hat 3} {:hat 2} {:hat 1}} Yes, this is just an API gap. Issue/patch welcome. --~--~-~--~~~---~--~~ You

Re: sorted-set-by?

2009-02-07 Thread Rich Hickey
On Feb 7, 2009, at 3:58 AM, puzzler wrote: Still, I think it's a good point that since Clojure has sorted-map-by, it seems logical to expect that it would also have sorted-set-by. Yes, this is just an API gap. Issue/patch welcome. Rich

Re: sorted-set-by?

2009-02-03 Thread R. P. Dillon
On further reflection, perhaps the best approach would use sorted-map: (defstruct example :msg :order) (def a (struct there 2)) (def b (struct hi 1)) (def c (struct everyone 3)) We want our map to be sorted on the :order key. So: (sorted-map (:order a) a (:order b) b (:order c) c) I could

Re: sorted-set-by?

2009-02-03 Thread Timothy Pratley
On further reflection, perhaps the best approach would use sorted-map: Just curious, does the key need to be in the struct? (seeing you'll get key-value pairs anyhow if you use first/last etc - the info will still be there) If you do need the key in both places, perhaps something like this

Re: sorted-set-by?

2009-02-03 Thread R. P. Dillon
Just curious, does the key need to be in the struct? (seeing you'll get key-value pairs anyhow if you use first/last etc - the info will still be there) Excellent point! Given that I'll be using a sorted-map now, I don't even need the structmap! Thanks for the code...I like what you did