Permalink
Browse files

Rename useful.alias to useful.ns, add var-name

  • Loading branch information...
1 parent 561efc7 commit d4b4c0514077c9535ddc2f7c39d9be8d0cd0e1b9 @amalloy amalloy committed Nov 8, 2011
Showing with 34 additions and 31 deletions.
  1. +0 −29 src/useful/alias.clj
  2. +1 −1 src/useful/core.clj
  3. +1 −1 src/useful/experimental/unicode.clj
  4. +32 −0 src/useful/ns.clj
View
@@ -1,29 +0,0 @@
-(ns useful.alias)
-
-(letfn [(var-name [v]
- (apply symbol (map str ((juxt (comp ns-name :ns)
- :name)
- (meta v)))))]
- (defn alias-var
- "Create a var with the supplied name in the current namespace, having the same
- metadata and root-binding as the supplied var."
- [name ^clojure.lang.Var var]
- (apply intern *ns* (with-meta name (merge {:dont-test (str "Alias of " (var-name var))}
- (meta var)
- (meta name)))
- (when (.hasRoot var) [@var]))))
-
-(defmacro defalias
- "Defines an alias for a var: a new var with the same root binding (if
- any) and similar metadata. The metadata of the alias is its initial
- metadata (as provided by def) merged into the metadata of the original."
- [dst src]
- `(alias-var (quote ~dst) (var ~src)))
-
-(defn alias-ns
- "Create vars in the current namespace to alias each of the public vars in
- the supplied namespace."
- [ns-name]
- (require ns-name)
- (doseq [[name var] (ns-publics (the-ns ns-name))]
- (alias-var name var)))
View
@@ -1,5 +1,5 @@
(ns useful.core
- (:use [useful.alias :only [alias-ns]]))
+ (:use [useful.ns :only [alias-ns]]))
(doseq [module '(bean cli compress datatypes debug dispatch experimental experimental.unicode fn java macro map parallel seq state string test utils)]
(alias-ns (symbol (str "useful." module))))
@@ -2,7 +2,7 @@
useful.experimental.unicode
(:use [useful.utils :only [map-entry]]
[useful.macro :only [macro-do]]
- [useful.alias :only [defalias]]))
+ [useful.ns :only [defalias]]))
(macro-do [dest src]
`(defalias ~dest ~src)
View
@@ -0,0 +1,32 @@
+(ns useful.ns)
+
+(defn var-name
+ "Get the namespace-qualified name of a var."
+ [v]
+ (apply symbol (map str ((juxt (comp ns-name :ns)
+ :name)
+ (meta v)))))
+
+(defn alias-var
+ "Create a var with the supplied name in the current namespace, having the same
+ metadata and root-binding as the supplied var."
+ [name ^clojure.lang.Var var]
+ (apply intern *ns* (with-meta name (merge {:dont-test (str "Alias of " (var-name var))}
+ (meta var)
+ (meta name)))
+ (when (.hasRoot var) [@var])))
+
+(defmacro defalias
+ "Defines an alias for a var: a new var with the same root binding (if
+ any) and similar metadata. The metadata of the alias is its initial
+ metadata (as provided by def) merged into the metadata of the original."
+ [dst src]
+ `(alias-var (quote ~dst) (var ~src)))
+
+(defn alias-ns
+ "Create vars in the current namespace to alias each of the public vars in
+ the supplied namespace."
+ [ns-name]
+ (require ns-name)
+ (doseq [[name var] (ns-publics (the-ns ns-name))]
+ (alias-var name var)))

0 comments on commit d4b4c05

Please sign in to comment.