dynadoc.example

(defexample k & args)

Defines one example code block for a symbol or an arbitrary piece of Clojure data. If `k` is not a namespace-qualified symbol or keyword, it will be associated with the current namespace.

Example

Define an example of a function in another namespace
(defexample clojure.core/+ "Add two numbers together" (+ 1 1))
Define an example of a function in the current namespace
(defexample parse-ns "Get the namespace from a symbol" (parse-ns 'my.namespace/asdf))
Define an example of a function with an assertion for testing
(defexample parse-ns {:doc "Get the namespace from a symbol", :ret (fn [n] (= n 'my.namespace))} (parse-ns 'my.namespace/asdf))

(defexample* k & args)

Like defexample, but a function instead of a macro

(defexamples k & examples)

Defines multiple example code blocks for a symbol or an arbitrary piece of Clojure data. If `k` is not a namespace-qualified symbol or keyword, it will be associated with the current namespace.

Example

Define multiple examples of the `conj` function
(defexamples clojure.core/conj ["Add a name to a vector" (conj ["Alice" "Bob"] "Charlie")] ["Add a number to a list" (conj '(2 3) 1)] [{:doc "Add a key-val pair to a hash map", :ret (fn [m] (= m {:name "Alice", :age 30}))} (conj {:name "Alice"} [:age 30])])

(defexamples* k & examples)

Like defexamples, but a function instead of a macro

(parse-ns k)

Example

Get the namespace from a symbol
(parse-ns 'my.namespace/asdf)