LiamRyan
LiamRyan

Reputation: 1898

What is the difference between (defn function-name) and (defn- function-name in 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))

Upvotes: 3

Views: 404

Answers (1)

Jan
Jan

Reputation: 11726

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.

Upvotes: 10

Related Questions