I posted this on IRC and Twitter yesterday, and response was
positive. If the list approves, I'll add it to Contrib. From there,
it can be considered for future versions of Clojure.
-SS
http://github.com/stuartsierra/need
need: a macro to load Clojure namespaces
The Need for need
=================
A lot of new Clojure users have trouble remembering the correct syntax
of use/require/refer.
The `need` macro is an attempt to simplify the process of loading
Clojure namespaces.
Unfortunately, `need` is not backwards-compatible with the existing
use/require/refer syntax. It would probably be too disruptive to
adopt this in Clojure right now, but it's an idea to think about for
the future.
I considered having `need` also replace `import` for Java classes, but
I think that loading Clojure namespaces and importing Java classes are
fundamentally different operations and should not be conflated.
Examples
--------
To load a namespace without referring any symbols:
(need
clojure.contrib.io)
To load a namespace and refer two symbols:
(need [
clojure.contrib.io reader writer])
To load a namespace and refer all symbols:
(need [
clojure.contrib.io :all])
To load a namespace and refer all symbols except one:
(need [
clojure.contrib.io :exclude [spit]])
To load a namespace and refer 3 symbols, renaming one of them. The
`:rename` map is like `{original-name new-name}`.
(need [
clojure.contrib.io reader writer
:rename {spit put-file}])
To load a namespace and alias it in the current namespace:
(need [
clojure.contrib.io :as io])
More
----
`need` does not support prefix lists because they are too confusing
when combined with vectors of symbols and make it hard to do
search-and-replace on namespace names.
`need*` is a function that behaves like `need` but evaluates its
arguments.
`need` and `need*` both accept the flags `:reload`, `:reload-all`, and
`:verbose`.
See additional documentation in the docstring of the `need` macro.
--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To post to this group, send email to
cloju...@googlegroups.com.
To unsubscribe from this group, send email to
clojure-dev...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/clojure-dev?hl=en.