blob: 92253eaf6db98a758215c58acc3aa7f6159c93ef (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
Container Types
===============
Apart from arrays and scopes, a few other container types are provided in the standard library.
Lists
-----
A list maps integers to arbitrary objects. Access to members takes time linear in the index.
A new list can be created with `list` and appended to with `append` or `append1` (the latter
will not distribute over domain having inputs).
list ==l
/a l .append
/b l .append
/c l .append
l dump
<scope: 0000600000533210>
l |dump each
"a"
"b"
"c"
l len dump
0000000000000003
list ==m
[ /a /b /c ] m .append1
m len dump
0000000000000001
Lists can be used similar to functions from integers or arrays. Just as with
arrays, negative indices start from the end of the list towards the beginning.
Write access is provided via `=[]` as usual.
list ==l
[ /a /b /c ] l .append
0 l * dump
"a"
1 neg l * dump
"c"
l dom dump
[
0000000000000000
0000000000000001
0000000000000002
]
/foo 1 l =[]
l |dump each
"a"
"foo"
"c"
l l { cat } '*0.0 |dump each
"aa"
"bb"
"cc"
List can be used like a stack via `pop`.
list ==l
[ /a /b /c ] l .append
l .pop
l |dump each
"a"
"b"
Maps
----
Maps wrap scopes to provide an array-like container mapping from strings to arbitrary objects.
A new map can be created with `map`, new members are added via `=[]` when the key does not exist
beforehand. Access to specific members works like in arrays via `*`. Testing for members can be
done via `has`.
map ==m
1 /foo m =[]
2 /bar m =[]
m dump
<scope: 0000600000533210>
m dom dump
[
"foo"
"bar"
]
m |dump each
0000000000000001
0000000000000002
/foo m * dump
0000000000000001
/foo m .has dump
0000000000000001
/FOO m .has dump
0000000000000000
m 2 mul ==m2
m2 dom dump
[
"foo"
"bar"
]
m2 |dump each
0000000000000002
0000000000000004
/foo m2 * dump
0000000000000002
Trees
-----
Trees provide mapping from keys to arbitrary objects,
keeping the keys in `lt`/`eq`/`gt` ascending order. Otherwise they should work just as maps.
tree ==t
1 /foo t =[]
2 /bar t =[]
t dump
<scope: 0000600000533210>
t dom dump
[
"bar"
"foo"
]
t |dump each
0000000000000002
0000000000000001
/foo t * dump
0000000000000001
/foo t .has dump
0000000000000001
/FOO t .has dump
0000000000000000
t 2 mul ==t2
t2 dom dump
[
"bar"
"foo"
]
t2 |dump each
0000000000000004
0000000000000002
/foo t2 * dump
0000000000000002
|