(careful-def sym form)
Given some namespace ns
, returns a function of some binding symbol and a
form to bind. The function returns either
A form like (def ~sym ~form)
, if sym
is not currently bound into ns
If sym
is bound already, returns a form that emits a warning and then
uses ns-unmap
and intern
to reassign the binding.
In Clojure, this behavior matches redefinitions of symbols bound in
clojure.core
. Symbols bound with def
that are already imported from other
namespaces cause an exception, hence this more careful workaround.
(In ClojureScript, only forms like (def ~sym ~form)
are emitted, since the
compiler does not currently error in case 2 and already handles emitting the
warning for us.)
Given some namespace `ns`, returns a function of some binding symbol and a form to bind. The function returns either - A form like `(def ~sym ~form)`, if `sym` is not currently bound into `ns` - If `sym` is bound already, returns a form that emits a warning and then uses `ns-unmap` and `intern` to reassign the binding. In Clojure, this behavior matches redefinitions of symbols bound in `clojure.core`. Symbols bound with `def` that are already imported from other namespaces cause an exception, hence this more careful workaround. (In ClojureScript, only forms like `(def ~sym ~form)` are emitted, since the compiler does not currently error in case 2 and already handles emitting the warning for us.)
(defgeneric name arities docstring? attr-map? & options)
Defines a multifn using the provided symbol. Arranges for the multifn
to answer the :arity message, reporting either [:exactly a]
or
[:between a b]
according to the arguments given.
arities
can be either a single or a vector of 2 numbers.The options
allowed differs slightly from defmulti
:
the first optional argument is a docstring.
the second optional argument is a dict of metadata. When you query the
defined multimethod with a keyword, it will pass that keyword along as a query
to this metadata map. (:arity
is always overridden if supplied, and :name
defaults to the symbol f
.)
Any remaining options are passed along to defmulti
.
Defines a multifn using the provided symbol. Arranges for the multifn to answer the :arity message, reporting either `[:exactly a]` or `[:between a b]` according to the arguments given. - `arities` can be either a single or a vector of 2 numbers. The `options` allowed differs slightly from `defmulti`: - the first optional argument is a docstring. - the second optional argument is a dict of metadata. When you query the defined multimethod with a keyword, it will pass that keyword along as a query to this metadata map. (`:arity` is always overridden if supplied, and `:name` defaults to the symbol `f`.) Any remaining options are passed along to `defmulti`.
(fork & {:keys [cljs clj]})
I borrowed this lovely, mysterious macro from macrovich
:
https://github.com/cgrand/macrovich. This allows us to fork behavior inside
of a macro at macroexpansion time, not at read time.
I borrowed this lovely, mysterious macro from `macrovich`: https://github.com/cgrand/macrovich. This allows us to fork behavior inside of a macro at macroexpansion time, not at read time.
(import-def sym)
(import-def sym var-name)
Given a regular def'd var from another namespace, defined a new var with the same name in the current namespace.
NOTE that this macro is taken
from potemkin.namespaces/import-def
with an additional internal branch for ClojureScript support. but meant to be
usable from ClojureScript. In ClojureScript, it's not possible to:
resolve
at macro-timeAnd therefore not possible to mirror the metadata from one var to another. This simplified version therefore suffices in the cljs case.
Given a regular def'd var from another namespace, defined a new var with the same name in the current namespace. NOTE that this macro is taken from [`potemkin.namespaces/import-def`](https://github.com/clj-commons/potemkin/blob/master/src/potemkin/namespaces.clj) with an additional internal branch for ClojureScript support. but meant to be usable from ClojureScript. In ClojureScript, it's not possible to: - alter the metadata of a var after definition - call `resolve` at macro-time And therefore not possible to mirror the metadata from one var to another. This simplified version therefore suffices in the cljs case.
(import-macro sym)
(import-macro sym name)
Given a macro in another namespace, defines a macro with the same name in the current namespace. Argument lists, doc-strings, and original line-numbers are preserved.
NOTE that import-macro
comes
from potemkin.namespaces
;
we import it here to avoid importing the full library.
Given a macro in another namespace, defines a macro with the same name in the current namespace. Argument lists, doc-strings, and original line-numbers are preserved. NOTE that [[import-macro]] comes from [`potemkin.namespaces`](https://github.com/clj-commons/potemkin/blob/master/src/potemkin/namespaces.clj); we import it here to avoid importing the full library.
(import-vars & imports)
import multiple defs from multiple namespaces. works for vars and fns, macros only work in Clojure.
NOTE that import-vars
is a copy
of potemkin.namespaces/import-vars
,
with an additional fork for ClojureScript support. The syntax is the same as
Potemkin's macro:
(import-vars
[m.n.ns1 a b]
[x.y.ns2 d e f]) =>
(def a m.n.ns1/a)
(def b m.n.ns1/b)
...
(def d m.n.ns2/d)
... etc
import multiple defs from multiple namespaces. works for vars and fns, macros only work in Clojure. NOTE that [[import-vars]] is a copy of [`potemkin.namespaces/import-vars`](https://github.com/clj-commons/potemkin/blob/master/src/potemkin/namespaces.clj), with an additional fork for ClojureScript support. The syntax is the same as Potemkin's macro: ```clj (import-vars [m.n.ns1 a b] [x.y.ns2 d e f]) => (def a m.n.ns1/a) (def b m.n.ns1/b) ... (def d m.n.ns2/d) ... etc ```
(link-vars src dst)
Makes sure that all changes to src
are reflected in dst
.
NOTE that link-vars
comes
from potemkin.namespaces
;
we import it here to avoid importing the full library.
Makes sure that all changes to `src` are reflected in `dst`. NOTE that [[link-vars]] comes from [`potemkin.namespaces`](https://github.com/clj-commons/potemkin/blob/master/src/potemkin/namespaces.clj); we import it here to avoid importing the full library.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close