such.ns
Makes working with namespaces easier.
+find-var
(+find-var name)
(+find-var ns name)
Return a variable identified by the arguments, or nil
. A version of the built-in function, but with a wider domain.
Case 1: If the single argument is a namespace-qualified symbol, the behavior is the same as clojure.core/find-var
: the variable of that name in that namespace is returned:
(+find-var 'clojure.core/even?) => #'clojure.core/even?
Note that the namespace must exist or an exception is thrown.
Strings with a single slash are treated as symbols:
(+find-var "clojure.core/even?") => #'clojure.core/even?
Namespace-qualified keywords can also be used.
Case 2: If the single argument is not namespace-qualified, it is treated as if it were qualified with *ns*
:
(+find-var 'find-var) => #'this.namespace/find-var
(+find-var "symbol") => #'this.namespace/symbol
Case 3: If the single argument is a var, it is returned.
Case 4: In the two-argument case, the ns
argument supplies the namespace and the name
argument the var’s name. ns
may be a namespace, symbol, keyword, or string (as-ns-symbol). name
may be a string, symbol, keyword, or var. In the first three cases, the namespace part of name
(if any) is ignored:
(+find-var 'such.wide-domains 'clojure.core/find-var) => #'such.wide-domains/find-var
(+find-var *ns* :find-var) => #'this.namespace/find-var
If the name
argument is a var, find-var
looks for a var with the same name in ns
:
(+find-var 'such.wide-domains #'clojure.core/find-var) => #'such.wide-domains/find-var
with-scratch-namespace
macro
(with-scratch-namespace ns-sym & body)
Create a scratch namespace named ns-name
, run body
within it, then remove it. ns-name
must be a symbol. If the namespace already exists, it will be removed, then recreated, then removed.