-
Notifications
You must be signed in to change notification settings - Fork 0
/
array.easy
160 lines (134 loc) · 2.96 KB
/
array.easy
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# Copyright (C) 2021 Matway Burkow
#
# This repository and all its contents belong to Matway Burkow (referred here and below as "the owner").
# The content is for demonstration purposes only.
# It is forbidden to use the content or any part of it for any purpose without explicit permission from the owner.
# By contributing to the repository, contributors acknowledge that ownership of their work transfers to the owner.
"control" useFile
"arrayRange" useFile
Array: [{
CONTAINER: {};
ARRAY:{};
data: ();
empty: [data fieldCount 0 =] func;
single: [data fieldCount 1 =] func;
pushBack: [
element:;
data element , drop
] func;
getSize: [
data fieldCount
] func;
popBack: [
data untail drop drop
] func;
shrink: [
newSize:;
[newSize getSize <] [
popBack
] while
] func;
enlarge: [
value:newSize:;;
[newSize getSize >] [
@value copy pushBack
] while
] func;
clear: [
() !data
] func;
at: [
index:;
index data @
] func;
set: [
value:index:;;
@value index @data !
] func;
first: [0 data @] func;
last: [getSize 1 - data @] func;
firstIter: [data 0 ArrayInternal.makeIterator] func;
lastIter: [data getSize 1 - ArrayInternal.makeIterator] func;
endIter: [data getSize ArrayInternal.makeIterator] func;
makeRange: [
data 0 getSize ArrayInternal.makeRange
] func;
makeRange: [empty] [() 0 0 ArrayInternal.makeRange] pfunc;
}] func;
enum: [drop 1 fieldName "ARRAY" =] [
enumArrayObject:enumArrayBody:;;
enumArrayObject.getSize 0 > [
i: 0;
[
i enumArrayObject.data @ @enumArrayBody call [
i 1 + !i i enumArrayObject.getSize <
] [
FALSE
] if
] loop
] when
] pfunc;
enumIter: [drop 1 fieldName "ARRAY" =] [
enumArrayObject:enumArrayBody:;;
enumArrayObject.getSize 0 > [
i: 0;
[
enumArrayObject.data i ArrayInternal.makeIterator @enumArrayBody call [
i 1 + !i i enumArrayObject.getSize <
] [
FALSE
] if
] loop
] when
] pfunc;
copy: [1 fieldName "ARRAY" =] [
src:;
dst: Array;
src [
copy dst.pushBack TRUE
] enum
dst
] pfunc;
@: [1 fieldName "ARRAY" =] [.at] pfunc;
!: [1 fieldName "ARRAY" =] [.set] pfunc;
fieldCount: [1 fieldName "ARRAY" =] [.getSize] pfunc;
=: [1 fieldName "ARRAY" =] [a1:a2:;;
a1.getSize a2.getSize =
[
ok: TRUE;
i: 0;
[i a1.getSize < ok and] [
i a1 @ i a2 @ = [i 1 + !i] [FALSE !ok] if
] while
ok
] [FALSE] if
] pfunc;
makeArray: [
value:count:;;
result: Array;
@value count result.enlarge
result
] func;
makeArrayByRange: [
.untail swap # t r'
result: makeArrayByRange; # t a
result.pushBack
result
] func;
makeArrayByRange: [.empty] [
drop
Array
] pfunc;
makeArray: [0 fieldName "RANGE" =] [
makeArrayByRange
] pfunc;
makeArray: [isPureList] [
list:;
result: Array;
i: 0;
[i list fieldCount <] [
i list @ result.pushBack
i 1 + !i
] while
result
] pfunc;