ClojureDocs

Nav

Namespaces

Creates and interns or locates a global var with the name of symbol and a
namespace of the value of the current namespace (*ns*). See
http://clojure.org/special_forms for more information.
8 Examples
user=> (def my-val 5)
#'user/my-val

user=> my-val
5
user=> (def my-function (fn [x] (* x x x)))
#'user/my-function
user=> (my-function 4)
64
;; This is an example of setting a docstring during a def.
;; (Note that the clojure.repl namespace which contains the
;;  doc function is not loaded by default in Emacs' SLIME mode.)

user> (def ted-nugent "The nuge rocks" 123)
#'user/ted-nugent
user> (doc ted-nugent)
-------------------------
user/ted-nugent
  The nuge rocks
user> ted-nugent
123
;; give function another name
user=> (def sys-map map)

;; give macro another name
user=> (def #^{:macro true} sys-loop #'loop)
;;Assign a Function to a Variable

(def say-hello
 (fn [name]
   (str "Hello " name)))

(say-hello "World")
;;"Hello World"


;;the same but using an anonymous function
(def say-hello
 #(str "Hello " %))

(say-hello "World")
;;"Hello World"


;;anonymous function using two arguments
(def hello-doc #(str "Hello " %1 %2))

(hello-doc "Dr." "House")
;;"Hello Dr.House"

;; Private var
(def ^:private foobar
  "I am the docstring."
  "I am the value.")

;; function checks: variable = 9 or not
user=> (def ?9 #(= % 9))
#'user/?9
user=> (?9 9)
true
user=> (?9 5)
false
; add a doc-string to your def variable
(def my-var "this is doc string for my var" "hello")

; add a doc-string using meta key `:doc` 
(def ^{:doc "this is doc string for my var"} my-var "hello") 
See Also

Same as (def name (fn [params* ] exprs*)) or (def name (fn ([params* ] exprs*)+)) with any doc-s...

Added by boxie

params => positional-params*, or positional-params* & rest-param positional-param => binding-form ...

Added by boxie

Like defn, but the resulting function name is declared as a macro and will be used as a macro by t...

Added by boxie

Creates a new multimethod with the associated dispatch function. The docstring and attr-map are op...

Added by boxie

defs name to have the root value of the expr iff the named var has no root value, else expr is une...

Added by Gitward

Removes the mappings for the symbol from the namespace.

Added by ryoakg
0 Notes
No notes for def