Andy Thanks. Makes complete sense when explained!
Thanks for the speedy reply. On Oct 2, 6:27 pm, Andy Fingerhut <andy.finger...@gmail.com> wrote: > user> (def a ["a" "a" "a" "b" "c" "c" "a"]) > #'user/a > user> (pack a) > (("a" "a" "a") ("b") ("c" "c") ("a")) > > Now calling (map f (pack a)) will cause the function you give as the > first argument of map to be called with each of the elements of the > collection (pack a) in turn. Those elements are, in order: > > ("a" "a" "a") a list of 3 elements > ("b") a list of 1 element (note: it is not the same as "b" by itself) > ("c" "c") a list of 2 elements > ("a") a list of 1 element > > Then each of the return values of those function calls will be put > into a list (or more precisely, a lazily generated list). > > With your failing version of encodemodifed, when it is called with the > list ("b"), (count %) is equal to 1, so it returns its argument, which > is the list ("b"). > > Andy > > On Oct 2, 2010, at 9:26 AM, swheeler wrote: > > > > > > > > > (defn pack > > [col] > > (partition-by identity > > col)) > > > (defn encodemodified > > [col] > > (map #(if (== (count %) 1) % (list (count %) (first > > %))) > > (pack col))) -- 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