on b93c19b help sign in
307 lines 3.7 kB history raw
1+++
2title = "2m: Container from Noun"
3weight = 16
4template = "doc.html"
5+++
6### `++ly`
8List from raw noun
10Takes a null-terminated noun and produces a `list`.
12#### Accepts
14`a` is a null-terminated noun.
16#### Produces
18A `list`.
20#### Source
22```
23 ++ ly
24 le:nl
25```
27#### Examples
29```
30 > (ly [1 2 3 ~])
31 ~[1 2 3]
33 > (ly "abc")
34 ~['a' 'b' 'c']
35```
37#### Discussion.
39`ly` is an alias for `le:nl`.
41---
42### `++my`
44Map from raw noun
46Takes a null-terminated noun and produces a `map.`
48#### Accepts
50`a` is a noun composed of ordered pairs and terminated with `~`.
52#### Produces
54A `map`.
56#### Source
58```
59 ++ my
60 my:nl
61```
63#### Examples
65```
66 > (my [['a' 1] ['b' 2] ~])
67 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
68```
70#### Discussion.
72`my` is an alias for `my:nl`.
74---
75### `++sy`
77Set from raw noun
79Takes a null-terminated noun and produces a `set`.
81#### Accepts
83`a` is a null-terminated noun.
85#### Produces
87A `set`.
89#### Source
91```
92 ++ sy
93 si:nl
94```
96#### Examples
98```
99 > (sy [1 2 3 ~])
100 [n=2 l={1 3} r={}]
102 > (sy (ly [1 2 3 ~]))
103 [n=2 l={1 3} r={}]
105 > (sy "abc")
106 [n='b' l={'a' 'c'} r={}]
107```
109#### Discussion.
111`sy` is an alias for `si:nl`.
113---
114### `++nl`
116Noun-to-container operations
118Core whose arms contain functions that create various typed nouns from raw
119nouns.
121#### Source
123```
124 ++ nl
125 |%
126```
128---
129### `++le:nl`
131Construct list
133Takes a null-terminated noun and produces a `list`.
135#### Accepts
137`a` is a null-terminated noun.
139#### Produces
141A list.
143#### Source
145```
146 ++ le
147 |* a=(list)
148 ^+ =< $
149 |% +- $ ?:(*? ~ [i=(snag 0 a) t=$])
150 --
151 a
152```
154#### Examples
156```
157 > (le:nl [1 2 3 ~])
158 ~[1 2 3]
160 > (le:nl "abc")
161 ~['a' 'b' 'c']
162```
164---
165### `++my:nl`
167Construct map
169Takes a null-terminated noun and produces a `map` of the same type of the `p`
170and `q` passed in.
172#### Accepts
174`a` is a noun composed of ordered pairs and terminated with `~`.
176#### Produces
178A map.
180#### Source
182```
183 ++ my
184 |* a=(list (pair))
185 => .(a ^+((le a) a))
186 (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
187```
189#### Examples
191```
192 > (my:nl [['a' 1] ['b' 2] ~])
193 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
194```
196---
197### `++si:nl`
199Construct set
201Takes a null-terminated noun and produces a `set`.
203#### Accepts
205`a` is a null-terminated noun.
207#### Produces
209A set.
211#### Source
213```
214 ++ si
215 |* a=(list)
216 => .(a ^+((le a) a))
217 (~(gas in `(set _i.-.a)`~) a)
218```
220#### Examples
222```
223 > (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
224 [n=['b' [2 3]] l={['a' 1]} r={}]
225```
227---
228### `++snag:nl`
230Index
232Produces the element at the index `a` of null-terminated noun `b` and failing if
233the noun is null. Lists are 0-indexed.
235#### Accepts
237`a` is a noun.
239`b` is a null-terminated noun.
241#### Produces
243A noun.
245#### Sources
247```
248 ++ snag
249 |* [a=@ b=(list)]
250 ?~ b
251 ~_ leaf+"snag-fail"
252 !!
253 ?: =(0 a) i.b
254 $(b t.b, a (dec a))
255```
257#### Examples
259```
260 > =b [[2 3] [1 4] ~]
261 > (snag:nl 0 b)
262 [2 3]
264 > (snag:nl 2 b)
265 ! snag-fail
266 ! exit
267```
269---
270### `++weld:nl`
272Concatenate
274Produces a list that is the concatenation of null-terminated nouns `a` and `b`.
276#### Accepts
278`a` is a null-terminated noun.
280`b` is a null-terminated noun.
282#### Produces
284A list.
286#### Source
288```
289 ++ weld
290 |* [a=(list) b=(list)]
291 => .(a ^+((le a) a), b ^+((le b) b))
292 =+ 42
293 |-
294 ?~ a b
295 [i=i.a t=$(a t.a)]
296```
298#### Examples
300```
301 > =b [[2 3] [1 4] ~]
303 > (weld:nl b [8 9 ~])
304 [i=[2 3] t=[i=[1 4] t=~[8 9]]]
305```
307---