Jump to content

Clojure Programming/Examples/API Examples/Variable Definition

From Wikibooks, open books for an open world
user=> (def x 4) 
#'user/x
user=> x
4
user=> (def y '(\a :b "c"))
#'user/y
user=> y
(\a :b "c")
user=> (def z (fn[] 3))
#'user/z
user=> (z)
3

binding

[edit | edit source]
user=> (def x 1)
#'user/x
user=> (def y 2)
#'user/y
user=> (def get-x-y (fn [] (list x y)))
#'user/get-x-y
user=> (get-x-y)
(1 2)
user=> (binding [x 100 y 200] (get-x-y))
(100 200)
user=> (get-x-y)
(1 2)