Hello, All in all, you only used in your first definition "core" clojure constructs, you avoided doing "imperative in clojure clothes". So, while not leveraging to its full extent the power of clojure standard library functions and higher-order-functions, your code certainly qualifies as functional and in the spirit of clojure.
2010/10/7 Stefan Rohlfing <stefan.rohlf...@gmail.com> > Dear Clojure Group, > > Following an Enlive tutorial I wanted to implement a function 'd-map' > that takes an arbitrary number of [:key (list of values)] parameters > like this: > > (d-map [:headline ["this" "is" "me"] ] > [:points [1 2 3] ] > [:comments [10 20 30] ]) > > > and returns a collection of [:key value] vectors where each value is > grouped with its respective key: > > [ [:headline "this"] [:headline "is"] [:headline "me"] > [:points 1] [:points 2] [:points 3] > [:comments 10] [:comments 20] [:comments 30] ] > > > I could only come up with the following implementation for 'd-map'. > Although it works it just does not 'feel' elegant of even very > functional: > > (defn d-map [& kfps] > (let [keys (map first kfps) > fns (map second kfps)] > (loop [keys keys fns fns res []] > (if (seq keys) > (recur (rest keys) (rest fns) > (into res (map (fn [x] [(first keys) x]) (first > fns)))) > res)))) > > I am relatively new to Clojure and want to learn how to write > idiomatic code. I therefore appreciate any alternative implementation > that might help me learn some new things. > > Stefan > > -- > 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<clojure%2bunsubscr...@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 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