| 1 |
#error THIS FILE IS NOW OBSOLETE - DO NOT USE. |
| 2 |
|
| 3 |
#include "tads.h" |
| 4 |
#include "t3.h" |
| 5 |
#include "array.h" |
| 6 |
#include "vector.h" |
| 7 |
|
| 8 |
preinit() |
| 9 |
{ |
| 10 |
} |
| 11 |
|
| 12 |
main(args) |
| 13 |
{ |
| 14 |
local x, y, z; |
| 15 |
local fib0, fib1; |
| 16 |
|
| 17 |
x = new Array(7).fillValue('A'); |
| 18 |
"create and fill:\n"; showArray(x); |
| 19 |
|
| 20 |
x = new Array([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); |
| 21 |
"initially: x = \n"; showArray(x); |
| 22 |
"\b"; |
| 23 |
|
| 24 |
y = x; |
| 25 |
y[3] = 100; |
| 26 |
"after modifying through reference: y = \n"; showArray(y); |
| 27 |
"x = \n"; showArray(x); |
| 28 |
"\b"; |
| 29 |
|
| 30 |
y = new Array(x, 1, 20); |
| 31 |
"new Array(x, 1, 20):\n"; showArray(y); |
| 32 |
"\b"; |
| 33 |
|
| 34 |
y = new Array(x, 1, 5); |
| 35 |
"new Array(x, 1, 5):\n"; showArray(y); |
| 36 |
"\b"; |
| 37 |
|
| 38 |
y = new Array(x, 3, 5); |
| 39 |
"new Array(x, 3, 5):\n"; showArray(y); |
| 40 |
"\b"; |
| 41 |
|
| 42 |
y = new Array(x, 5, 20); |
| 43 |
"new Array(x, 5, 20):\n"; showArray(y); |
| 44 |
"\b"; |
| 45 |
|
| 46 |
y = x.toList(); |
| 47 |
"toList:\n"; showList(y); |
| 48 |
"\b"; |
| 49 |
|
| 50 |
y = x.toList(5); |
| 51 |
"toList(5):\n"; showList(y); |
| 52 |
"\b"; |
| 53 |
|
| 54 |
y = x.toList(17); |
| 55 |
"toList(17):\n"; showList(y); |
| 56 |
"\b"; |
| 57 |
|
| 58 |
y = x.toList(15, 17); |
| 59 |
"toList(15, 17):\n"; showList(y); |
| 60 |
"\b"; |
| 61 |
|
| 62 |
y = x.toList(3, 5); |
| 63 |
"toList(3, 5):\n"; showList(y); |
| 64 |
"\b"; |
| 65 |
|
| 66 |
y = x.toList(10, 8); |
| 67 |
"toList(10, 8):\n"; showList(y); |
| 68 |
"\b"; |
| 69 |
|
| 70 |
y = new Array(x); |
| 71 |
"direct copy:\n"; showArray(y); |
| 72 |
"\b"; |
| 73 |
|
| 74 |
y.copyFrom(['a', 'b', 'c', 'd'], 1, 3, 7); |
| 75 |
"copyFrom 1,3,7:\n"; showArray(y); |
| 76 |
"\b"; |
| 77 |
|
| 78 |
y = new Array(x); |
| 79 |
y.copyFrom(['a', 'b', 'c', 'd'], 1, 7, 7); |
| 80 |
"copyFrom 1,7,7:\n"; showArray(y); |
| 81 |
"\b"; |
| 82 |
|
| 83 |
y = new Array(x); |
| 84 |
y.copyFrom(['a', 'b', 'c', 'd'], 1, 4, 3); |
| 85 |
"copyFrom 1,4,3:\n"; showArray(y); |
| 86 |
"\b"; |
| 87 |
|
| 88 |
y = new Array(x); |
| 89 |
y.copyFrom(['a', 'b', 'c', 'd'], 3, 5, 7); |
| 90 |
"copyFrom 3,5,7:\n"; showArray(y); |
| 91 |
"\b"; |
| 92 |
|
| 93 |
y = new Array(10); |
| 94 |
y.fillValue('x'); |
| 95 |
"fillValue 'x':\n"; showArray(y); |
| 96 |
"\b"; |
| 97 |
|
| 98 |
y = new Array(10); |
| 99 |
y.fillValue(123, 3); |
| 100 |
"fillValue 123, 3:\n"; showArray(y); |
| 101 |
"\b"; |
| 102 |
|
| 103 |
y = new Array(10); |
| 104 |
y.fillValue('abc', 3, 4); |
| 105 |
"fillValue 'abc', 3, 4:\n"; showArray(y); |
| 106 |
"\b"; |
| 107 |
|
| 108 |
fib0 = 1; |
| 109 |
fib1 = 1; |
| 110 |
y = new Array(20).applyAll(new function(x) |
| 111 |
{ local ret = fib0; fib0 = fib1; fib1 += ret; return ret; }); |
| 112 |
"applyAll fibonacci:\n"; showArray(y); |
| 113 |
"\b"; |
| 114 |
|
| 115 |
"Subset >= 10:\n"; showArray(y.subset({x: x >= 10})); |
| 116 |
"\b"; |
| 117 |
|
| 118 |
"find where x > 10: <<y.indexWhich({x: x > 10})>>\n"; |
| 119 |
"find where x > 100: <<y.indexWhich({x: x > 100})>>\n"; |
| 120 |
"find where x > 10000: <<y.indexWhich({x: x > 10000})>>\n"; |
| 121 |
"\b"; |
| 122 |
|
| 123 |
x = y.mapAll({x: x + 1}); |
| 124 |
"mapAll plus one:\n"; showArray(x); |
| 125 |
"mapAll == orig? <<x == y ? 'yes' : 'no'>>\n"; |
| 126 |
"mapAll original:\n"; showArray(y); |
| 127 |
"\b"; |
| 128 |
|
| 129 |
"indexOf 1: <<y.indexOf(1)>>\n"; |
| 130 |
"indexOf 54: <<y.indexOf(54)>>\n"; |
| 131 |
"indexOf 55: <<y.indexOf(55)>>\n"; |
| 132 |
"indexOf 6765: <<y.indexOf(6765)>>\n"; |
| 133 |
"\b"; |
| 134 |
|
| 135 |
"lastIndexOf 1: <<y.lastIndexOf(1)>>\n"; |
| 136 |
"lastIndexOf 54: <<y.lastIndexOf(54)>>\n"; |
| 137 |
"lastIndexOf 55: <<y.lastIndexOf(55)>>\n"; |
| 138 |
"lastIndexOf 6765: <<y.lastIndexOf(6765)>>\n"; |
| 139 |
"\b"; |
| 140 |
|
| 141 |
"lastIndexWhich(x < 1): <<y.lastIndexWhich({x: x < 1})>>\n"; |
| 142 |
"lastIndexWhich(x < 2): <<y.lastIndexWhich({x: x < 2})>>\n"; |
| 143 |
"lastIndexWhich(x < 10): <<y.lastIndexWhich({x: x < 10})>>\n"; |
| 144 |
"lastIndexWhich(x < 100): <<y.lastIndexWhich({x: x < 100})>>\n"; |
| 145 |
"lastIndexWhich(x < 10000): <<y.lastIndexWhich({x: x < 10000})>>\n"; |
| 146 |
"\b"; |
| 147 |
|
| 148 |
"lastValWhich(x < 1): <<y.lastValWhich({x: x < 1})>>\n"; |
| 149 |
"lastValWhich(x < 2): <<y.lastValWhich({x: x < 2})>>\n"; |
| 150 |
"lastValWhich(x < 10): <<y.lastValWhich({x: x < 10})>>\n"; |
| 151 |
"lastValWhich(x < 100): <<y.lastValWhich({x: x < 100})>>\n"; |
| 152 |
"lastValWhich(x < 10000): <<y.lastValWhich({x: x < 10000})>>\n"; |
| 153 |
"\b"; |
| 154 |
|
| 155 |
"countOf 0: <<y.countOf(0)>>\n"; |
| 156 |
"countOf 1: <<y.countOf(1)>>\n"; |
| 157 |
"countOf 55: <<y.countOf(55)>>\n"; |
| 158 |
"\b"; |
| 159 |
|
| 160 |
"countWhich x>10: <<y.countWhich({x: x > 10})>>\n"; |
| 161 |
"countWhich x>100: <<y.countWhich({x: x > 100})>>\n"; |
| 162 |
"countWhich x>1000: <<y.countWhich({x: x > 1000})>>\n"; |
| 163 |
"countWhich x>10000: <<y.countWhich({x: x > 10000})>>\n"; |
| 164 |
"\b"; |
| 165 |
|
| 166 |
x = new Array([2, 4, 6, 8, 10, 12]); |
| 167 |
"initially: x = \n"; showArray(x); |
| 168 |
"getUnique:\n"; showArray(x.getUnique()); |
| 169 |
|
| 170 |
x = new Array([9, 1, 9, 2, 9, 3, 9, 2, 9, 1, 9]); |
| 171 |
"initially: x = \n"; showArray(x); |
| 172 |
"getUnique:\n"; showArray(x.getUnique()); |
| 173 |
|
| 174 |
"\b"; |
| 175 |
|
| 176 |
x = new Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); |
| 177 |
y = new Array([2, 4, 6, 8, 10, 12, 14, 16, 18, 20]); |
| 178 |
"appendUnique:\n"; showArray(x.appendUnique(y)); |
| 179 |
|
| 180 |
y = new Array([11, 12, 13, 14, 15]); |
| 181 |
"appendUnique:\n"; showArray(x.appendUnique(y)); |
| 182 |
|
| 183 |
y = new Array([2, 4, 6, 8, 10]); |
| 184 |
"appendUnique:\n"; showArray(x.appendUnique(y)); |
| 185 |
|
| 186 |
"appendUnique - list:\n"; |
| 187 |
"appendUnique:\n"; showArray(x.appendUnique([5, 10, 15, 20])); |
| 188 |
|
| 189 |
"\b"; |
| 190 |
|
| 191 |
y = new Array(['hello', 'there', 'how', 'are', 'you', 'today']); |
| 192 |
"sort:\n"; showArray(y.sort()); |
| 193 |
|
| 194 |
"sort descending:\n"; showArray(y.sort(true)); |
| 195 |
|
| 196 |
"\b"; |
| 197 |
|
| 198 |
x = new Array([1, 1, 2, 3, 5, 8, 13]); |
| 199 |
y = [101, 102, 103]; |
| 200 |
z = x + y; |
| 201 |
"adding list to array:\n"; showArray(z); |
| 202 |
|
| 203 |
y = new Vector(5); |
| 204 |
y += [987, 654, 321]; |
| 205 |
z = x + y; |
| 206 |
"adding vector to array:\n"; showArray(z); |
| 207 |
|
| 208 |
y = new Array([111, 222, 333]); |
| 209 |
z = x + y; |
| 210 |
"adding array to array:\n"; showArray(z); |
| 211 |
|
| 212 |
y = [2, 3, 5, 8]; |
| 213 |
z = x - y; |
| 214 |
"subtracting list from array:\n"; showArray(z); |
| 215 |
|
| 216 |
y = new Vector(5); |
| 217 |
y += [1, 13]; |
| 218 |
z = x - y; |
| 219 |
"subtracting vector from array:\n"; showArray(z); |
| 220 |
|
| 221 |
y = new Array([1, 3, 5]); |
| 222 |
z = x - y; |
| 223 |
"subtracting array from array:\n"; showArray(z); |
| 224 |
} |
| 225 |
|
| 226 |
showArray(x) |
| 227 |
{ |
| 228 |
for (local i = 1 ; i <= x.length() ; ++i) |
| 229 |
"\t[<<i>>] = <<showVal(x[i])>>\n"; |
| 230 |
} |
| 231 |
|
| 232 |
showList(x) |
| 233 |
{ |
| 234 |
for (local i = 1 ; i <= x.length() ; ++i) |
| 235 |
"\t[<<i>>] = <<showVal(x[i])>>\n"; |
| 236 |
} |
| 237 |
|
| 238 |
showVal(x) |
| 239 |
{ |
| 240 |
if (x == nil) |
| 241 |
"nil"; |
| 242 |
else |
| 243 |
tadsSay(x); |
| 244 |
} |
| 245 |
|