We had this exact discussion just yesterday.

I'd suggest forgetting about the technical details, how comp works etc. for
a minute. And think about what we're dealing with.

1. If we are dealing with functions, function composition makes sense to be
written left to right and applied right to left. If you were working on
paper this would feel natural to you. And that's exactly how comp works.

2. When we're dealing with transducers, they are functions under the hood
but you know they're not functions that take a value and return another
value[1]. Anyway that's an implementation detail. Rich describes
transducers as processes, or steps of instructions. Natural way to deal
with these things is to write them top to bottom or left to right and then
assume they'll be applied in that same order[2].

1: A transducer is a function that takes another transducer or a step
function and returns a function that wraps it. If I'm not mistaken second
application takes a collection and returns a reducing function on that
collection. But I'm probably wrong.

2: How does the order change? I hope this incomplete example helps:

;; applied in reverse order
(defn f [g]
  (fn [coll]
    (g (do-something coll))))


;; f is applied before g, like transducer composition
(comp f g)


;; applied in given order
(defn k [j]
  (fn [coll]
    (do-something (j coll))))

;; j is applied before k, like function composition
(comp k j)





On Thu, Oct 30, 2014 at 11:44 PM, Mars0i <marsh...@logical.net> wrote:

> Caveat: I am still feeling around in the dark in my understanding of
> transducers.  What I write below may just convey how clueless I am.
>
> (Meta-caveat: I'm probably spitting into the wind.  I should no doubt use
> my time more wisely.)
>
>
> Normal function composition is done starting from the right.  This is
> familiar from mathematics, other Lisps, most languages, and it's how
> Clojure's function application and 'comp' work.
>
> Sometimes it's easier to understand composition going from left to right,
> as in many natural languages and as in unix pipes, and Clojure provides
> '->' and '->>' to do that.  That's good.  Best of both worlds.  One thing I
> like about these operators is that their name clearly indicates the
> direction of function application.
>
> Transducers allow function composition with potential efficiency gains,
> but apply functions starting from left to right.  But *it does this using
> the name 'comp'*, which otherwise applies functions from right to left.
> What??  Doesn't that seem like a Bad Thing?  Why not use a different name?
> (It's like overloading the minus sign so that in some contexts, it
> subtracts the first argument from the second.)
>
> (Is Clojure is getting too popular?  Its essential features--prefix
> notation, parentheses, purely functional operations, and laziness--aren't
> doing enough to scare away Java programmers?  :-)
>
> --
> 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.
>



-- 
Kind Regards,
Atamert Ölçgen

-+-
--+
+++

www.muhuk.com

-- 
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.

Reply via email to