Private def in clojure / clojurescript

In Clojure and clojurescript, you might have a personal version of defn called defn-, but how do you do the same for def, since def doesn't seem to turn on?

+48
clojure clojurescript
Dec 07 '13 at 16:16
source share
4 answers

You must add a pair of key values :private true metadata.

 (def ^{:private true} some-var :value) ;; or (def ^:private some-var :value) 

The second form is just short for the first.

+64
Dec 07 '13 at 16:29
source share

If you want to define, here's how to implement it

 (defmacro def- [item value] `(def ^{:private true} ~item ~value) ) 
+14
Aug 03 '14 at 12:51 on
source share

It is worth noting that currently in ClojureScript there can be no private def (and defn ): https://clojurescript.org/about/differences (under "special forms")

Compilation will not fail, but def will remain available.

+14
Nov 23 '14 at 21:45
source share

There is a discussion on this topic in this google post group. Apparently, the request has been considered. According to one answer, defn- it was believed that this was not a good idea, and decided not to perpetuate it with def and others.

+4
Aug 17 '15 at 18:26
source share



All Articles