on 4fdc19d help sign in
316 lines 3.6 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---
44## `++my`
46Map from raw noun
48Takes a null-terminated noun and produces a `map.`
50#### Accepts
52`a` is a noun composed of ordered pairs and terminated with `~`.
54#### Produces
56A `map`.
58#### Source
60```hoon
61 ++ my
62 my:nl
63```
65#### Examples
67```
68 > (my [['a' 1] ['b' 2] ~])
69 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
70```
72#### Discussion
74`my` is an alias for `my:nl`.
76---
78## `++sy`
80Set from raw noun
82Takes a null-terminated noun and produces a `set`.
84#### Accepts
86`a` is a null-terminated noun.
88#### Produces
90A `set`.
92#### Source
94```hoon
95 ++ sy
96 si:nl
97```
99#### Examples
101```
102 > (sy [1 2 3 ~])
103 [n=2 l={1 3} r={}]
105 > (sy (ly [1 2 3 ~]))
106 [n=2 l={1 3} r={}]
108 > (sy "abc")
109 [n='b' l={'a' 'c'} r={}]
110```
112#### Discussion
114`sy` is an alias for `si:nl`.
116---
118## `++nl`
120Noun-to-container operations
122Core whose arms contain functions that create various typed nouns from raw
123nouns.
125#### Source
127```hoon
128 ++ nl
129 |%
130```
132---
134### `++le:nl`
136Construct list
138Takes a null-terminated noun and produces a `list`.
140#### Accepts
142`a` is a null-terminated noun.
144#### Produces
146A list.
148#### Source
150```hoon
151++ le
152 |* a=(list)
153 ^+ =< $
154 |@ ++ $ ?:(*? ~ [i=(snag 0 a) t=$])
155 --
156 a
157```
159#### Examples
161```
162 > (le:nl [1 2 3 ~])
163 ~[1 2 3]
165 > (le:nl "abc")
166 ~['a' 'b' 'c']
167```
169---
171### `++my:nl`
173Construct map
175Takes a null-terminated noun and produces a `map` of the same type of the `p`
176and `q` passed in.
178#### Accepts
180`a` is a noun composed of ordered pairs and terminated with `~`.
182#### Produces
184A map.
186#### Source
188```hoon
189++ my
190 |* a=(list (pair))
191 => .(a ^+((le a) a))
192 (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
193```
195#### Examples
197```
198 > (my:nl [['a' 1] ['b' 2] ~])
199 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
200```
202---
204### `++si:nl`
206Construct set
208Takes a null-terminated noun and produces a `set`.
210#### Accepts
212`a` is a null-terminated noun.
214#### Produces
216A set.
218#### Source
220```hoon
221++ si
222 |* a=(list)
223 => .(a ^+((le a) a))
224 (~(gas in `(set _i.-.a)`~) a)
225```
227#### Examples
229```
230 > (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
231 [n=['b' [2 3]] l={['a' 1]} r={}]
232```
234---
236### `++snag:nl`
238Index
240Produces the element at the index `a` of null-terminated noun `b` and failing if
241the noun is null. Lists are 0-indexed.
243#### Accepts
245`a` is a noun.
247`b` is a null-terminated noun.
249#### Produces
251A noun.
253#### Sources
255```hoon
256++ snag
257 |* [a=@ b=(list)]
258 ?~ b
259 ~_ leaf+"snag-fail"
260 !!
261 ?: =(0 a) i.b
262 $(b t.b, a (dec a))
263```
265#### Examples
267```
268 > =b [[2 3] [1 4] ~]
269 > (snag:nl 0 b)
270 [2 3]
272 > (snag:nl 2 b)
273 ! snag-fail
274 ! exit
275```
277---
279### `++weld:nl`
281Concatenate
283Produces a list that is the concatenation of null-terminated nouns `a` and `b`.
285#### Accepts
287`a` is a null-terminated noun.
289`b` is a null-terminated noun.
291#### Produces
293A list.
295#### Source
297```hoon
298++ weld
299 |* [a=(list) b=(list)]
300 => .(a ^+((le a) a), b ^+((le b) b))
301 =+ 42
302 |-
303 ?~ a b
304 [i=i.a t=$(a t.a)]
305```
307#### Examples
309```
310 > =b [[2 3] [1 4] ~]
312 > (weld:nl b [8 9 ~])
313 [i=[2 3] t=[i=[1 4] t=~[8 9]]]
314```
316---