Assignment: let

When you are creating functions, you may want to assign names to values in order to reuse those values or make your code more readable.

Inside of a function, however, you should not use def, like you would outside of a function. Instead, you should use a special form called let.

(defn average [values]
  (let [c (count values)
        s (reduce + values)]
    (/ s c)))

(average [1.0 1.0 2.0 3.0 5.0])

results matching ""

    No results matching ""