In Clojure and clojurescript you can have a private version of defn called defn-, but how do you do the same for def, as def- doesn't seem to be included?
You have to add the :private true
metadata key value pair.
(def ^{:private true} some-var :value)
;; or
(def ^:private some-var :value)
The second form is just a short-hand for the first one.
It's worth mentioning, that currently it's not possible to have a private def
(and defn
) in ClojureScript: https://clojurescript.org/about/differences (under "special forms")
Compilation won't fail and but the def
will stay accessible.
If you want a def-, here's how to implement it
(defmacro def- [item value]
`(def ^{:private true} ~item ~value)
)
This google group post has a discussion about this topic. Apparently the request has been considered. According to one of the responses, defn-
was deemed to not be a good idea and decided not to perpetuate it with def
and others.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With