| description | Functions for creating typed containers (lists, maps, sets) from raw nouns. | |||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| layout |
|
A +list from raw $noun.
Takes a null-terminated $noun and produces a +list.
.a is a null-terminated $noun.
A +list.
++ ly
le:nl> (ly [1 2 3 ~])
~[1 2 3]
> (ly "abc")
~['a' 'b' 'c']
+ly is an alias for +le:nl.
Map from raw $noun.
Takes a null-terminated $noun and produces a +map.
.a is a $noun composed of ordered pairs and terminated with ~.
A +map.
++ my
my:nl> (my [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]
Note that +my is an alias for +my:nl.
Set from raw $noun.
Takes a null-terminated $noun and produces a +set.
.a is a null-terminated $noun.
A +set.
++ sy
si:nl> (sy [1 2 3 ~])
[n=2 l={1 3} r={}]
> (sy (ly [1 2 3 ~]))
[n=2 l={1 3} r={}]
> (sy "abc")
[n='b' l={'a' 'c'} r={}]
+sy is an alias for +si:nl.
Noun-to-container operations.
Core whose arms contain functions that create various typed $nouns from raw $nouns.
++ nl
|%Construct +list.
Takes a null-terminated $noun and produces a +list.
.a is a null-terminated $noun.
A +list.
++ le
|* a=(list)
^+ =< $
|@ ++ $ ?:(*? ~ [i=(snag 0 a) t=$])
--
a> (le:nl [1 2 3 ~])
~[1 2 3]
> (le:nl "abc")
~['a' 'b' 'c']
Construct +map.
Takes a null-terminated $noun and produces a +map of the same type of the .p and .q passed in.
.a is a $noun composed of ordered pairs and terminated with ~.
A +map.
++ my
|* a=(list (pair))
=> .(a ^+((le a) a))
(~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)> (my:nl [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]
Construct +set.
Takes a null-terminated $noun and produces a +set.
.a is a null-terminated $noun.
A +set.
++ si
|* a=(list)
=> .(a ^+((le a) a))
(~(gas in `(set _i.-.a)`~) a)> (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
[n=['b' [2 3]] l={['a' 1]} r={}]
Index.
Produces the element at the index .a of null-terminated $noun .b and failing if the $noun is null. +lists are 0-indexed.
.a is a $noun.
.b is a null-terminated $noun.
A $noun.
++ snag
|* [a=@ b=(list)]
?~ b
~_ leaf+"snag-fail"
!!
?: =(0 a) i.b
$(b t.b, a (dec a))> =b [[2 3] [1 4] ~]
> (snag:nl 0 b)
[2 3]
> (snag:nl 2 b)
! snag-fail
! exit
Concatenate.
Produces a +list that is the concatenation of null-terminated $nouns .a and .b.
.a is a null-terminated $noun.
.b is a null-terminated $noun.
A +list.
++ weld
|* [a=(list) b=(list)]
=> .(a ^+((le a) a), b ^+((le b) b))
=+ 42
|-
?~ a b
[i=i.a t=$(a t.a)]> =b [[2 3] [1 4] ~]
> (weld:nl b [8 9 ~])
[i=[2 3] t=[i=[1 4] t=~[8 9]]]