on master help sign in
Merge pull request #293 from urbit/rmariani-patch-24
6270ca0Joshua Reagan
docs/hoon/library/2m.md+270−1
@@ -2,5 +2,274 @@
2navhome: /docs/
2navhome: /docs/
3---
3---
4
4
5−
6# 2m: container from noun
5# 2m: container from noun
6+
7+### `++ly`
8+
9+List from raw noun
10+
11+Takes a null-terminated noun and produces a `list`.
12+
13+#### Accepts
14+
15+`a` is a null-terminated noun.
16+
17+#### Produces
18+
19+A `list`.
20+
21+#### Source
22+
23+ ++ ly
24+ le:nl
25+
26+#### Examples
27+
28+ > (ly [1 2 3 ~])
29+ ~[1 2 3]
30+
31+ > (ly "abc")
32+ ~['a' 'b' 'c']
33+
34+#### Discussion.
35+
36+`ly` is an alias for `le:nl`.
37+
38+***
39+### `++my`
40+
41+Map from raw noun
42+
43+Takes a null-terminated noun and produces a `map.`
44+
45+#### Accepts
46+
47+`a` is a noun composed of ordered pairs and terminated with `~`.
48+
49+#### Produces
50+
51+A `map`.
52+
53+#### Source
54+
55+ ++ my
56+ my:nl
57+
58+#### Examples
59+
60+ > (my [['a' 1] ['b' 2] ~])
61+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
62+
63+#### Discussion.
64+
65+`my` is an alias for `my:nl`.
66+
67+***
68+### `++sy`
69+
70+Set from raw noun
71+
72+Takes a null-terminated noun and produces a `set`.
73+
74+#### Accepts
75+
76+`a` is a null-terminated noun.
77+
78+#### Produces
79+
80+A `set`.
81+
82+#### Source
83+
84+ ++ sy
85+ si:nl
86+
87+#### Examples
88+
89+ > (sy [1 2 3 ~])
90+ [n=2 l={1 3} r={}]
91+
92+ > (sy (ly [1 2 3 ~]))
93+ [n=2 l={1 3} r={}]
94+
95+ > (sy "abc")
96+ [n='b' l={'a' 'c'} r={}]
97+
98+#### Discussion.
99+
100+`sy` is an alias for `si:nl`.
101+
102+***
103+### `++nl`
104+
105+Noun-to-container operations
106+
107+Core whose arms contain functions that create various typed nouns from raw
108+nouns.
109+
110+#### Source
111+
112+ ++ nl
113+ |%
114+
115+***
116+### `++le:nl`
117+
118+Construct list
119+
120+Takes a null-terminated noun and produces a `list`.
121+
122+#### Accepts
123+
124+`a` is a null-terminated noun.
125+
126+#### Produces
127+
128+A list.
129+
130+#### Source
131+
132+ ++ le
133+ |* a=(list)
134+ ^+ =< $
135+ |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
136+ --
137+ a
138+
139+#### Examples
140+
141+ > (le:nl [1 2 3 ~])
142+ ~[1 2 3]
143+
144+ > (le:nl "abc")
145+ ~['a' 'b' 'c']
146+
147+***
148+### `++my:nl`
149+
150+Construct map
151+
152+Takes a null-terminated noun and produces a `map` of the same type of the `p`
153+and `q` passed in.
154+
155+#### Accepts
156+
157+`a` is a noun composed of ordered pairs and terminated with `~`.
158+
159+#### Produces
160+
161+A map.
162+
163+#### Source
164+
165+ ++ my
166+ |* a=(list (pair))
167+ => .(a ^+((le a) a))
168+ (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
169+
170+#### Examples
171+
172+ > (my:nl [['a' 1] ['b' 2] ~])
173+ [n=[p='b' q=2] l={[p='a' q=1]} r={}]
174+
175+***
176+### `++si:nl`
177+
178+Construct set
179+
180+Takes a null-terminated noun and produces a `set`.
181+
182+#### Accepts
183+
184+`a` is a null-terminated noun.
185+
186+#### Produces
187+
188+A set.
189+
190+#### Source
191+
192+ ++ si
193+ |* a=(list)
194+ => .(a ^+((le a) a))
195+ (~(gas in `(set _i.-.a)`~) a)
196+
197+#### Examples
198+
199+ > (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
200+ [n=['b' [2 3]] l={['a' 1]} r={}]
201+
202+***
203+### `++snag:nl`
204+
205+Index
206+
207+Produces the element at the index `a` of null-terminated noun `b` and failing if
208+ the noun is null. Lists are 0-indexed.
209+
210+#### Accepts
211+
212+`a` is a noun.
213+
214+`b` is a null-terminated noun.
215+
216+#### Produces
217+
218+A noun.
219+
220+#### Sources
221+
222+ ++ snag
223+ |* [a=@ b=(list)]
224+ ?~ b
225+ ~_ leaf+"snag-fail"
226+ !!
227+ ?: =(0 a) i.b
228+ $(b t.b, a (dec a))
229+
230+#### Examples
231+
232+ > =b [[2 3] [1 4] ~]
233+ > (snag:nl 0 b)
234+ [2 3]
235+
236+ > (snag:nl 2 b)
237+ ! snag-fail
238+ ! exit
239+
240+***
241+#### `++weld:nl`
242+
243+Concatenate
244+
245+Produces a list that is the concatenation of null-terminated nouns `a` and `b`.
246+
247+#### Accepts
248+
249+`a` is a null-terminated noun.
250+
251+`b` is a null-terminated noun.
252+
253+#### Produces
254+
255+A list.
256+
257+#### Source
258+
259+ ++ weld
260+ |* [a=(list) b=(list)]
261+ => .(a ^+((le a) a), b ^+((le b) b))
262+ =+ 42
263+ |-
264+ ?~ a b
265+ [i=i.a t=$(a t.a)]
266+
267+#### Examples
268+
269+ > =b [[2 3] [1 4] ~]
270+
271+ > (weld:nl b [8 9 ~])
272+ [i=[2 3] t=[i=[1 4] t=~[8 9]]]
273+
274+
275+***