On Dec 11, 10:33 pm, Richard Newman <holyg...@gmail.com> wrote: > > (reduce (fn [model f] (assoc model f (inc (get model f 1)))) > > {} features)) > > > Do Clojurians usually arrange like that? Can it be rearrange for more > > understandability? > > I can't speak for everyone, but I don't think it's common to jam > *everything* on one line. I imagine Rich was laying out for space on > slides. > > For maximum readability I would arrange that thusly: > > (reduce > (fn [model f] > (assoc model > f (inc (get model f 1)))) > {} > features)) > > or, less verbosely > > (reduce > (fn [model f] > (assoc model f (inc (get model f 1)))) > {} features))
Or one could be ridiculously verbose: (reduce #(let [[model feature] %& val (get model feature 1) val (inc val)] (assoc model feature val)) {} features) Its worth noting that the only reason for these extra steps is that, unlike get, update-in doesn't take a not-found arg (much to my chagrin). If it had a signature as has recently been discussed (http://groups.google.com/group/clojure/browse_thread/thread/ 99cc4a6bfe665a6e), then the code could simplified down to: (reduce #(update-in %1 [%2] 2 inc) {} features) -- 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