Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between (defn function-name) and (defn- function-name in clojure?

Tags:

clojure

Can someone explain this to me? I think I understand that (defn -main) is declaring a main method that would be recognised by Java and that if you use this in conjunction with a namespace with (:gen-class) that you can fool Java into thinking clojure is object oriented, however I can't work out what the purpose is if you just create a function like

(def- add2 (partial + 2) )

or (defn- my-function...)

Can anyone explain this simply or correct me if the above assumptions are wrong?

**Edit - I understand what a partial function does :) I'm just wondering if there's a difference between above and (def add2 (partial + 2))

like image 307
LiamRyan Avatar asked Jul 14 '26 10:07

LiamRyan


1 Answers

Functions defined with defn- aren't accessible outside of the namespace they were defined in. In other words, they are private.

Take a look at the source of defn-. This macro evaluates to a call to defn with {:private true} merged into the metadata hash.

like image 70
Jan Avatar answered Jul 17 '26 19:07

Jan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!