on c19bc7a help sign in
312 lines 3.7 kB history raw
1:- :~ navhome/'/docs/'
2 sort/'16'
3 title/'2m: Container from Noun'
4 ==
6;>
9# 2m: container from noun
11### `++ly`
13List from raw noun
15Takes a null-terminated noun and produces a `list`.
17#### Accepts
19`a` is a null-terminated noun.
21#### Produces
23A `list`.
25#### Source
27```
28 ++ ly
29 le:nl
30```
32#### Examples
34```
35 > (ly [1 2 3 ~])
36 ~[1 2 3]
38 > (ly "abc")
39 ~['a' 'b' 'c']
40```
42#### Discussion.
44`ly` is an alias for `le:nl`.
46---
47### `++my`
49Map from raw noun
51Takes a null-terminated noun and produces a `map.`
53#### Accepts
55`a` is a noun composed of ordered pairs and terminated with `~`.
57#### Produces
59A `map`.
61#### Source
63```
64 ++ my
65 my:nl
66```
68#### Examples
70```
71 > (my [['a' 1] ['b' 2] ~])
72 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
73```
75#### Discussion.
77`my` is an alias for `my:nl`.
79---
80### `++sy`
82Set from raw noun
84Takes a null-terminated noun and produces a `set`.
86#### Accepts
88`a` is a null-terminated noun.
90#### Produces
92A `set`.
94#### Source
96```
97 ++ sy
98 si:nl
99```
101#### Examples
103```
104 > (sy [1 2 3 ~])
105 [n=2 l={1 3} r={}]
107 > (sy (ly [1 2 3 ~]))
108 [n=2 l={1 3} r={}]
110 > (sy "abc")
111 [n='b' l={'a' 'c'} r={}]
112```
114#### Discussion.
116`sy` is an alias for `si:nl`.
118---
119### `++nl`
121Noun-to-container operations
123Core whose arms contain functions that create various typed nouns from raw
124nouns.
126#### Source
128```
129 ++ nl
130 |%
131```
133---
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```
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---
170### `++my:nl`
172Construct map
174Takes a null-terminated noun and produces a `map` of the same type of the `p`
175and `q` passed in.
177#### Accepts
179`a` is a noun composed of ordered pairs and terminated with `~`.
181#### Produces
183A map.
185#### Source
187```
188 ++ my
189 |* a=(list (pair))
190 => .(a ^+((le a) a))
191 (~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)
192```
194#### Examples
196```
197 > (my:nl [['a' 1] ['b' 2] ~])
198 [n=[p='b' q=2] l={[p='a' q=1]} r={}]
199```
201---
202### `++si:nl`
204Construct set
206Takes a null-terminated noun and produces a `set`.
208#### Accepts
210`a` is a null-terminated noun.
212#### Produces
214A set.
216#### Source
218```
219 ++ si
220 |* a=(list)
221 => .(a ^+((le a) a))
222 (~(gas in `(set _i.-.a)`~) a)
223```
225#### Examples
227```
228 > (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
229 [n=['b' [2 3]] l={['a' 1]} r={}]
230```
232---
233### `++snag:nl`
235Index
237Produces the element at the index `a` of null-terminated noun `b` and failing if
238the noun is null. Lists are 0-indexed.
240#### Accepts
242`a` is a noun.
244`b` is a null-terminated noun.
246#### Produces
248A noun.
250#### Sources
252```
253 ++ snag
254 |* [a=@ b=(list)]
255 ?~ b
256 ~_ leaf+"snag-fail"
257 !!
258 ?: =(0 a) i.b
259 $(b t.b, a (dec a))
260```
262#### Examples
264```
265 > =b [[2 3] [1 4] ~]
266 > (snag:nl 0 b)
267 [2 3]
269 > (snag:nl 2 b)
270 ! snag-fail
271 ! exit
272```
274---
275#### `++weld:nl`
277Concatenate
279Produces a list that is the concatenation of null-terminated nouns `a` and `b`.
281#### Accepts
283`a` is a null-terminated noun.
285`b` is a null-terminated noun.
287#### Produces
289A list.
291#### Source
293```
294 ++ weld
295 |* [a=(list) b=(list)]
296 => .(a ^+((le a) a), b ^+((le b) b))
297 =+ 42
298 |-
299 ?~ a b
300 [i=i.a t=$(a t.a)]
301```
303#### Examples
305```
306 > =b [[2 3] [1 4] ~]
308 > (weld:nl b [8 9 ~])
309 [i=[2 3] t=[i=[1 4] t=~[8 9]]]
310```
312---