Liking cljdoc? Tell your friends :D

title: Block sidebar_label: Block

Let block

Let blocks provide lexical scope to all nested elements. Associated bindings are key value pairs, with key either symbol or destructuring patterns. Values can be primitive types or references to queries.

(let [a 1
      {name :name} [status.user]]
  [view {}
   [text {}
    name]])

Destructuring

Sequential data structure

Extract seq elements by index Elements can be ignored with _ :as symbol denotes the whole sequence

Examples

[[a _ c :as all] [1 2 3 4 5]]
;; a = 1
;; c = 3
;; all = [1 2 3 4 5]

Associative data structure

Extract map values by keys {a :a} Optional values via [a 5] No namespaced keyword support, no short syntax

Examples

[{a :a a :b [c 4] :c :as all} {:a 1 :b 2 :d 3}]
;; a = 1
;; b = 2
;; c = 4
;; all = {:a 1 :b 2 :d 3}

Nesting

Both structure type destrucuring can be combined

[{[a1 _ a3] :a {d :d #{f 7} :f [[_ g2] 8}] :b [_ e2] :e :all all}
 {:a [1 2 3] :b {:d 4 :e [5 6] :g [9 10]}}]
;; a1 = 1
;; a3 = 3
;; d = 4
;; e2 = 5
;; f = 7
;; g2 = 10
;; all = {:a [1 2 3] :b {:d 4 :e [5 6] :g [9 10]}}

Can you improve this documentation?Edit on GitHub

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

× close