+ return self;
+end
+
+function array_methods:append(array)
+ local len,len2 = #self, #array;
+ for i=1,len2 do
+ self[len+i] = array[i];
+ end
+ return self;
+end
+
+function array_methods:push(x)
+ t_insert(self, x);
+ return self;
+end
+
+function array_methods:pop(x)
+ local v = self[x];
+ t_remove(self, x);
+ return v;
+end
+
+function array_methods:concat(sep)
+ return t_concat(array.map(self, tostring), sep);
+end
+
+function array_methods:length()
+ return #self;
+end
+
+--- These methods always create a new array
+function array.collect(f, s, var)
+ local t = {};
+ while true do
+ var = f(s, var);
+ if var == nil then break; end
+ t_insert(t, var);
+ end
+ return setmetatable(t, array_mt);
+end
+
+---
+
+-- Setup methods from array_base
+for method, f in pairs(array_base) do
+ local base_method = f;
+ -- Setup global array method which makes new array
+ array[method] = function (old_a, ...)
+ local a = new_array();
+ return base_method(a, old_a, ...);
+ end
+ -- Setup per-array (mutating) method
+ array_methods[method] = function (self, ...)
+ return base_method(self, self, ...);
+ end