Thanks, Konrad and Andrew, for chipping in!

>> There's an outline of an implementation of multisets (I think that's
>> the same as your bags) at:
>>
>>        http://code.google.com/p/clojure-contrib/source/browse/trunk/src/
>> clojure/contrib/types/examples.clj

Thanks for the pointer.

I apologize for the negativity, but these don't seem "first class" --  
that is, I can't treat them as I would sets:

user=> (map identity #{:a :b :c})
(:a :c :b)
user=> (map identity (gc/conj (multiset {}) :a :b :c)))
([:c 1] [:b 1] [:a 1])

The cardinality tracking has been (necessarily, I understand) lifted  
into the explicit contents of the data structure, so applications  
which call Clojure code that performs core operations (not your  
generic versions) on those structures will not work.

Consequently, I couldn't use these with clojure.set's relational  
operations, for example:

user=> (clojure.set/join
          #{{:name "John" :id 4} {:name "John" :id 3}}
          #{{:age 32 :id 4} {:age 19 :id 3}})
#{{:age 19, :name "John", :id 3} {:age 32, :name "John", :id 4}}

user=> (clojure.set/join
          (gc/conj (multiset {}) {:name "John" :id 4} {:name  
"John" :id 3})
          (gc/conj (multiset {}) {:age 32 :id 4} {:age 19 :id 3}))
java.lang.ClassCastException: clojure.lang.PersistentArrayMap cannot  
be cast to java.util.Map$Entry (NO_SOURCE_FILE:0)

So far as I understand it, to get 'native' multisets would require an  
implementation of IPersistentCollection, or perhaps IPersistentSet  
itself (if the contract of the interface doesn't impose set  
semantics), and ideally some Clojure surface syntax.

PersistentTreeSet doesn't look too scary, so perhaps I'll dive in...  
more fun than my paid work, after all :)


> Google Collections has Multisets - and they have an immutable
> implementation.
>
> http://code.google.com/p/google-collections/

Hmm, interesting. Not sure how their builder-based approach would fit  
in.

For now, as I'm storing maps in my sets -- I'm doing relational stuff,  
after all -- I just add an :id entry in each map, filled by (iterate  
inc 0). Functionally the same as a multiset, so long as I ignore  
the :id 'column'...

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

Reply via email to