Yes, you can make any symbol private. If you look at the definition of
defn- you'll see all it does is set the :private metadata entry on the
function's name to true:
(defmacro defn-
"same as defn, yielding non-public def"
[name & decls]
(list* `defn (with-meta name (assoc (meta name) :private true)) decls))
This bears repeating as it may not be obious: symbols *themselves* are
set private, not the functions (or other values) they are bound to.
So you could do the same when defining a multimethod, just give the name
(symbol) of the method the metadata ":private" with the value "true":
(defmulti #{:private true} my-multi my-dispatch)
I'm having a bad day for typos, the example should of course be:
(defmulti #^{:private true} my-multi my-dispatch)
I'd tentatively agree. Although perhaps another model would be to just
put your semi-private declarations in a different namespace which is not
normally :use'd.
If you're really desperate you can get around the exception like this:
user> (apples/foo 4)
var: #'apples/foo is not public
[Thrown class java.lang.IllegalStateException]
user> (defmacro reveal [sym]
`(deref ~(clojure.lang.Compiler/resolveIn *ns* sym true)))
user> ((reveal apples/foo) 4)
But that's no doubt a bad idea.
I think we need some notion of semi-private as well. It would be ignored by :use and by automation like tab-completion of symbols, doc generation, and the like (except it would show in tab-completion inside of its namespace) but would not actually be illegal to invoke from elsewhere. So, it would be like private in every respect except for invokability.The purpose being so that you can make support functions (and perhaps other things) for macros without cluttering up the publicly-visible symbols list of the namespace, that is the set exported via :use and :require :as and affecting tab-completion and documentation generation.
How would you declare a namespace within a namespace? Or two namespaces in the same file?
I hate juggling through files, like C++ header and body files annoy me a lot.
Maybe you're right in not recommending this, but I find it at first glance to be quite nice. Now, I wouldn't keep switching namespace back and forth, but having two sections in the file, one the public API at the top, and everything else at the bottom in a private namespace, that's quite nice I'd say.
I hate juggling through files, like C++ header and body files annoy me a lot.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clo...@googlegroups.com
Note that posts from new members are moderated - please be patient with your first post.
To unsubscribe from this group, send email to
clojure+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups "Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.