Hi, > On Oct 27, 2016, at 9:54 AM, JHacks <jhackswo...@gmail.com> wrote: > > I have some confusion about how the function `comp` works, especially as > compared to the threading macro `->>`. > > From the book *Clojure Programming* (pages 70-71 of Chapter 2: Functional > Programming), the following two functions are described as functionally > equivalent: > > (def camel->keyword > (comp keyword > str/join > (partial interpose \-) > (partial map str/lower-case) > #(str/split % #"(?<=[a-z])(?=[A-Z])"))) > > (defn camel->keyword* > [s] > (->> (str/split s #"(?<=[a-z])(?=[A-Z])") > (map str/lower-case) > (interpose \-) > str/join > keyword)) > > Why does the first function, `camel->keyword`, need to use `partial` with the > `map` and `interpose` functions? The second function, `camel->keyword*`, does > not need to use `partial`.
comp takes a number of functions and returns a function. Threading macros take a number of forms (expressions) and return an expression. The threading macro does not need a partial, because it operates on the form and injects something in it (in the second position for ->, last position for ->>). The comp version does need a partial, because `(interpose \-)` is not a function — it is just a form. lvh > > -- > 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 > <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 > <mailto:clojure+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. -- 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/d/optout.