Liking cljdoc? Tell your friends :D

sicmutils.util.def


careful-defclj/s≠

clj
(careful-def ns)
cljs
(careful-def _)

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.)
sourceraw docstring

defgenericclj/s≠macro

clj
(defgeneric name arities docstring? attr-map? & options)
cljs
(defgeneric f arities & 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`.
sourceraw docstring

import-defclj/smacro

(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.

This macro is modeled after potemkin.namespaces/import-def 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.

Given a regular def'd var from another namespace, defined a new var with the
 same name in the current namespace.

This macro is modeled after `potemkin.namespaces/import-def` 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.
sourceraw docstring

import-varsclj/smacro

(import-vars & imports)

import multiple defs from multiple namespaces. works for vars and fns. not macros.

import-vars has the same syntax as potemkin.namespaces/import-vars:

(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. not
macros.

[[import-vars]] has the same syntax as `potemkin.namespaces/import-vars`:

 ```clojure
(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
```
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close