Thursday, February 18, 2010

Thoughts on namespace management

Konrad Hinsen recently posted some ideas for handling namespaces

http://onclojure.com/2010/02/17/managing-namespaces

There are a lot of good ideas in there, and right now I'd like to talk specifically about the proposed :like & :clone clauses.  I have a bit of a different approach.

Supposed we add a new project file, namespace_config.clj.  It would be a basic rules engine for configuring namespaces.  I'm thinking there would be a macro, extend-ns, that is roughly defined as follows. The exact implementation needs work.

(defmacro extend-ns
[pred & ns-clauses]
(if (pred a-ns)
(let [clauses (apply hash-map ns-clauses)]
`(do
(import ~@(:import clauses))
(use ~@(:use clauses))
(require ~@(:require ))))))
view raw ns-rules.clj hosted with ❤ by GitHub


This lets us set up a series of predicates & resulting actions that would be applied to each ns in the project. Everything would be done in one central location, so (hopefully) that would cut down on maintenance.