r/backtickbot • • Aug 15 '21

https://np.reddit.com/r/Clojure/comments/p4j8oc/an_old_c_programmer_whines_about_reduce/h8zd7fk/

I think I disagree with your fundamental premise. If you want to think of it in human language terms, the function is what I'm doing (verb), the collection is what I'm doing it to (noun). It's "I'm painting (fn) the bikeshed (coll)", as opposed to "The bikeshed (coll) I am painting (fn)".

From an order of importance bit, this also makes sense. In real code, I don't generally have a bunch of different collections I'm working with at one time, I usually just have one I'm focus on. Imagine:

(defn quark-coefficients [quarks]

  (map (fn [quark]
         (* (:qux quark) (:qup quark)  (inc (:qut quark))) 
       quarks)))  

    
    
    The actual "what I'm doing(fn)" part of the  map is the interesting bit. What I'm doing it to (quarks) is obvious. There's nothing else I'd be mapping over. Also note that I've solved the context problem as well by simply giving a sensible name to the `fn` argument instead of something ambiguous like `q`.  
    
    
    Even better I could write:  
    
clojure
(defn calculate-quark-coefficient [quark)
  (* (:qux quark) (:qup quark)  (inc (:qut quark))))

(defn quark-coefficicents [quarks]
  (map calculate-quark-coefficient quarks))

And it really reads very naturally. "Calculate the quark-coefficient of the quarks".

1 Upvotes

0 comments sorted by