Hi folks, I've recently found myself having to choose between dividing functionality between many specific namespaces, or having a few very generic namespaces. In theory, being specific is the better choice, as it allows users to more accurately pick what they want to use. But if most of the time you import library X, you'd also like W, Y and Z, you start to end up with a lot of lines of code just loading libraries.
Because I like to have my cake and eat it too, I wanted to keep my specific namespaces, but also group them up in more generic ones. To this end, I've created an "immigrate" function that interns every public symbol in a namespace into the current namespace: (defn- merge-meta! "Destructively merge metadata from a source object into a target." [source target] (.setMeta target (merge (meta source) (select-keys (meta target) [:name :ns])))) (defn immigrate "Add all the public vars in a list of namespaces to the current namespace." [& namespaces] (doseq [ns namespaces] (require ns) (doseq [[sym v] (ns-publics (find-ns ns))] (merge-meta! v (if (.isBound v) (intern *ns* sym (var-get v)) (intern *ns* sym)))))) The idea is that you can bundle up a set of specific libraries into a more general package, so your users don't have to type so much if they just want the defaults. - James --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---