2m: Container from Noun

++ly

List from raw noun

Takes a null-terminated noun and produces a list.

Accepts

a is a null-terminated noun.

Produces

A list.

Source

++ ly
le:nl

Examples

> (ly [1 2 3 ~])
~[1 2 3]
> (ly "abc")
~['a' 'b' 'c']

Discussion

ly is an alias for le:nl.


++my

Map from raw noun

Takes a null-terminated noun and produces a map.

Accepts

a is a noun composed of ordered pairs and terminated with ~.

Produces

A map.

Source

++ my
my:nl

Examples

> (my [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]

Discussion

my is an alias for my:nl.


++sy

Set from raw noun

Takes a null-terminated noun and produces a set.

Accepts

a is a null-terminated noun.

Produces

A set.

Source

++ sy
si:nl

Examples

> (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={}]

Discussion

sy is an alias for si:nl.


++nl

Noun-to-container operations

Core whose arms contain functions that create various typed nouns from raw nouns.

Source

++ nl
|%

++le:nl

Construct list

Takes a null-terminated noun and produces a list.

Accepts

a is a null-terminated noun.

Produces

A list.

Source

++ le
|* a=(list)
^+ =< $
|@ ++ $ ?:(*? ~ [i=(snag 0 a) t=$])
--
a

Examples

> (le:nl [1 2 3 ~])
~[1 2 3]
> (le:nl "abc")
~['a' 'b' 'c']

++my:nl

Construct map

Takes a null-terminated noun and produces a map of the same type of the p and q passed in.

Accepts

a is a noun composed of ordered pairs and terminated with ~.

Produces

A map.

Source

++ my
|* a=(list (pair))
=> .(a ^+((le a) a))
(~(gas by `(map _p.i.-.a _q.i.-.a)`~) a)

Examples

> (my:nl [['a' 1] ['b' 2] ~])
[n=[p='b' q=2] l={[p='a' q=1]} r={}]

++si:nl

Construct set

Takes a null-terminated noun and produces a set.

Accepts

a is a null-terminated noun.

Produces

A set.

Source

++ si
|* a=(list)
=> .(a ^+((le a) a))
(~(gas in `(set _i.-.a)`~) a)

Examples

> (si:nl `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
[n=['b' [2 3]] l={['a' 1]} r={}]

++snag:nl

Index

Produces the element at the index a of null-terminated noun b and failing if the noun is null. Lists are 0-indexed.

Accepts

a is a noun.

b is a null-terminated noun.

Produces

A noun.

Sources

++ snag
|* [a=@ b=(list)]
?~ b
~_ leaf+"snag-fail"
!!
?: =(0 a) i.b
$(b t.b, a (dec a))

Examples

> =b [[2 3] [1 4] ~]
> (snag:nl 0 b)
[2 3]
> (snag:nl 2 b)
! snag-fail
! exit

++weld:nl

Concatenate

Produces a list that is the concatenation of null-terminated nouns a and b.

Accepts

a is a null-terminated noun.

b is a null-terminated noun.

Produces

A list.

Source

++ weld
|* [a=(list) b=(list)]
=> .(a ^+((le a) a), b ^+((le b) b))
=+ 42
|-
?~ a b
[i=i.a t=$(a t.a)]

Examples

> =b [[2 3] [1 4] ~]
> (weld:nl b [8 9 ~])
[i=[2 3] t=[i=[1 4] t=~[8 9]]]