A typical situation in a Clojure project is that several namespaces
start with the same combination of use-require-import, or at least
have much of these references to the outside world in common. However,
Clojure currently has no way to define a combination of external
references once and then re-use and extend it in individual namespaces.
An attempt at a solution is provided by the nstools library:
http://code.google.com/p/clj-nstools/
http://clojars.org/nstools
Nstools permits any namespace to serve as a template for constructing
other namespaces. An enhanced version of the ns macro adds the "like"
clause. Suppose you have a namespace foo that serves as the template:
(ns foo
(:use [clojure.contrib.monads :exclude (cont-m)])
(:require [clojure.contrib.seq :as su])
(:import (java.io InputStream)))
You can then create a namespace bar and make it "like foo". This takes
over all the references created by the use, require, and import
clauses in foo, including aliases defined by :require ... :as:
(clojure.core/use 'nstools.ns)
(ns+ bar
(:like foo))
; Use the alias su
(prn (su/flatten [[1 2] [3 4]]))
In the long run, I hope to see something like that (or better) in
Clojure itself, as namespace management by an external library is
inevitably a bit messy (such as requiring the "use" before the "ns+").
For now, I'd like to get feedback and ideas for improvements!
Konrad.
--
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
Note that posts from new members are moderated - please be patient with your
first post.
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