The most similar thing that I can think of in Clojure, to the "statement that does nothing" from imperative programming, will be a function that does nothing. There are several built-in modules that can help you: identity is a function with one argument that simply returns its argument, and constantly is a higher order function that takes a value and returns a function that will take any number of arguments and return that value . Both of them are useful as placeholders in situations where you need to pass a function, but you do not want this function to actually perform most of everything. A simple example:
(defn twizzle [x] (let [f (cond (even? x) (partial * 4) (= 0 (rem x 3)) (partial + 2) :else identity)] (f (inc x))))
Rewriting this function as “do nothing” in the default case, although this is possible, will require inconvenient rewriting without using identity .
source share