Tassilo Horn wrote: > Erebus Mons <erebus.m...@gmail.com> writes: > >> I am reading in a csv-file, and then transform the attributes into a >> hash-map: >> >> __________________________________________________________________________ >> name,property1,property2,etc >> John,drunk,stinks,etc. >> etc. >> __________________________________________________________________________ >> >> {"John" {:property1 "drunk", :property2 "stinks"} etc > > Why a map of maps and not a map of sets, e.g.: > > {"John" #{"drunk" "stings"}}
Because I need to know what kind of property the properties are > > Then your predicates just turn into membership checks instead of having > to search through the values of the properties map. That is, drunk? is > just: > > (defn drunk? [person-prop-map person] > (contains? (person-prop-map person) "drunk)) > >> then I create with a function functions like drunk?, so that I can >> check whether John is drunk >> >> (drunk? "John") >> true >> >> I need to be able to get all properties in the map but >> drunk?. Therefore, I thought it would be handy to be able to filter >> out drunk? from the functions, but I figured I can only do that if I >> can treat the function-name like a name... > > You need to filter it out in order not to define the same function > several times, or do I get you wrong? > > If so, why not get the unique set of properties after building the map, > and then generate one predicate for any property that occured? > > ;; If the props are storted as sets like suggested above, then... > (apply clojure.set/union (vals person-prop-map)) > ;; ...gives you the set of unique property names. This is what I do already (but within a map of maps). Once I have defined the predicates (which works), I partition elements that satisfy a sub-property (e.g., drunk?) and those that don't. Now that I explain that, I might just draw a random property, and then I would not need the function stringify... But I was intrigued - I assumed that stringifying a function-name should be easy to do. Thank you! > > HTH, > Tassilo > -- -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.