Question

I am learning Clojure and using Clojure 1.5.1. It seems Clojure 1.5.1 no longer has the defnk macro. So, what is the equivalent for defnk in Clojure 1.5.1 ?

Was it helpful?

Solution

defnk once resided in clojure-contrib, but didn't make the jump into a new package when clojure-contrib was splitted up into multiple packages.

Instead of defnk you could use :keys/:or yourself to create default values for your function arguments, so

(defnk f [:b 43] (inc b))

becomes

(defn f [& {:keys [b] :or {b 1}}] (inc b))

If you don't like it this way, nothing stops you from taking the source of defnk and use it yourself.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top