mirror of
https://github.com/status-im/pluto.git
synced 2026-08-31 12:31:08 +00:00
1.2 KiB
1.2 KiB
title, sidebar_label
| title | sidebar_label |
|---|---|
| Block | 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]}}