on 979ae21 help sign in
308 lines 3.7 kB history raw
1+++
2title = "2m: Container from Noun"
3weight = 16
4template = "doc.html"
5+++
7### `++ly`
9List from raw noun
11Takes a null-terminated noun and produces a `list`.
13#### Accepts
15`a` is a null-terminated noun.
17#### Produces
19A `list`.
21#### Source
23```hoon
24 ++ ly
25 le:nl
26```
28#### Examples
30```
31 > (ly [1 2 3 ~])
32 ~[1 2 3]
34 > (ly "abc")
35 ~['a' 'b' 'c']
36```
38#### Discussion
40`ly` is an alias for `le:nl`.
42---
43### `++my`
45Map from raw noun
47Takes a null-terminated noun and produces a `map.`
49#### Accepts
51`a` is a noun composed of ordered pairs and terminated with `~`.
53#### Produces
55A `map`.
57#### Source
59```hoon
60 ++ my
61 my:nl
62```
64#### Examples
66```
67 > (my [['a' 1] ['b' 2] ~])
68 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
69```
71#### Discussion
73`my` is an alias for `my:nl`.
75---
76### `++sy`
78Set from raw noun
80Takes a null-terminated noun and produces a `set`.
82#### Accepts
84`a` is a null-terminated noun.
86#### Produces
88A `set`.
90#### Source
92```hoon
93 ++ sy
94 si:nl
95```
97#### Examples
99```
100 > (sy [1 2 3 ~])
101 [n=2 l={1 3} r={}]
103 > (sy (ly [1 2 3 ~]))
104 [n=2 l={1 3} r={}]
106 > (sy "abc")
107 [n='b' l={'a' 'c'} r={}]
108```
110#### Discussion
112`sy` is an alias for `si:nl`.
114---
115### `++nl`
117Noun-to-container operations
119Core whose arms contain functions that create various typed nouns from raw
120nouns.
122#### Source
124```hoon
125 ++ nl
126 |%
127```
129---
130### `++le:nl`
132Construct list
134Takes a null-terminated noun and produces a `list`.
136#### Accepts
138`a` is a null-terminated noun.
140#### Produces
142A list.
144#### Source
146```hoon
147 ++ le
148 |* a=(list)
149 ^+ =< $
150 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
151 --
152 a
153```
155#### Examples
157```
158 > (le:nl [1 2 3 ~])
159 ~[1 2 3]
161 > (le:nl "abc")
162 ~['a' 'b' 'c']
163```
165---
166### `++my:nl`
168Construct map
170Takes a null-terminated noun and produces a `map` of the same type of the `p`
171and `q` passed in.
173#### Accepts
175`a` is a noun composed of ordered pairs and terminated with `~`.
177#### Produces
179A map.
181#### Source
183```hoon
184 ++ my
185 |* a=(list (pair))
186 => .(a ^+((le a) a))
187 (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
188```
190#### Examples
192```
193 > (my:nl [['a' 1] ['b' 2] ~])
194 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
195```
197---
198### `++si:nl`
200Construct set
202Takes a null-terminated noun and produces a `set`.
204#### Accepts
206`a` is a null-terminated noun.
208#### Produces
210A set.
212#### Source
214```hoon
215 ++ si
216 |* a=(list)
217 => .(a ^+((le a) a))
218 (~(gas in `(set _i.-.a)`~) a)
219```
221#### Examples
223```
224 > (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
225 [n=['b' [2 3]] l={['a' 1]} r={}]
226```
228---
229### `++snag:nl`
231Index
233Produces the element at the index `a` of null-terminated noun `b` and failing if
234the noun is null. Lists are 0-indexed.
236#### Accepts
238`a` is a noun.
240`b` is a null-terminated noun.
242#### Produces
244A noun.
246#### Sources
248```hoon
249 ++ snag
250 |* [a=@ b=(list)]
251 ?~ b
252 ~_ leaf+"snag-fail"
253 !!
254 ?: =(0 a) i.b
255 $(b t.b, a (dec a))
256```
258#### Examples
260```
261 > =b [[2 3] [1 4] ~]
262 > (snag:nl 0 b)
263 [2 3]
265 > (snag:nl 2 b)
266 ! snag-fail
267 ! exit
268```
270---
271### `++weld:nl`
273Concatenate
275Produces a list that is the concatenation of null-terminated nouns `a` and `b`.
277#### Accepts
279`a` is a null-terminated noun.
281`b` is a null-terminated noun.
283#### Produces
285A list.
287#### Source
289```hoon
290 ++ weld
291 |* [a=(list) b=(list)]
292 => .(a ^+((le a) a), b ^+((le b) b))
293 =+ 42
294 |-
295 ?~ a b
296 [i=i.a t=$(a t.a)]
297```
299#### Examples
301```
302 > =b [[2 3] [1 4] ~]
304 > (weld:nl b [8 9 ~])
305 [i=[2 3] t=[i=[1 4] t=~[8 9]]]
306```
308---