Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

defnk is missing in Clojure 1.5.1

Tags:

clojure

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 ?

like image 453
Nipun Talukdar Avatar asked Mar 19 '23 17:03

Nipun Talukdar


1 Answers

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.

like image 149
sloth Avatar answered Mar 28 '23 02:03

sloth