Search code examples
clojure

Clojure: Increment every item of a list/vector by its first element


My try:

(defn inc-by-f [v]
      map #(+ (first v) %) v)

EDIT

(The original question was stupid; I missed the parenthesis. I am still leaving the question, so that perhaps I learn some new ways to deal with it.)

(defn inc-by-f [v]
  (map #(+ (first v) %) v))

What other cool “Clojure” ways to achieve the desired result?


Solution

  • You're missing parentheses around the map invocation. The following works as you expect:

    (defn inc-by-f [v]
      (map #(+ (first v) %) v))