Clojure's code seems idiomatic in my opinion, but it does a lot of unnecessary work. Here is an alternative way.
(reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2)) user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.180778 msecs" 5456 user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.255972 msecs" 5456 user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.346192 msecs" 5456 user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.162615 msecs" 5456 user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.257901 msecs" 5456 user=> (time (reduce #(+ %1 (* %2 %2)) 0 (range 1 32 2))) "Elapsed time: 0.175507 msecs" 5456
You really cannot conclude that one is faster than the other based on this test. Benchmarking is a difficult game. You need to test your programs in production environments at high cost in order to get any meaningful results.
What is the difference (decrease +) and (apply +) in Clojure?
apply is a higher order function with arity variable. Its first argument is a function of the arity variable, takes up a bunch of intermediate arguments, and then the last arg should be a list of args. It works by first inserting intermediate arguments into the argument list, then passing arguments to the function.
Example:
(apply + 0 1 2 3 '(4 5 6 7)) => (apply + '(0 1 2 3 4 5 6 7)) => (+ 0 1 2 3 4 5 6 7) => result
As for reduce , I think the docs say it explicitly
user=> (doc reduce) ------------------------- clojure.core/reduce ([f coll] [f val coll]) f should be a function of 2 arguments. If val is not supplied, returns the result of applying f to the first 2 items in coll, then applying f to that result and the 3rd item, etc. If coll contains no items, f must accept no arguments as well, and reduce returns the result of calling f with no arguments. If coll has only 1 item, it is returned and f is not called. If val is supplied, returns the result of applying f to val and the first item in coll, then applying f to that result and the 2nd item, etc. If coll contains no items, returns val and f is not called. nil
There are situations where you could use either apply f coll or reduce f coll , but usually I use apply when f has the arity variable and reduce when f is a 2-ary function.