summaryrefslogtreecommitdiff
path: root/std
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-25 22:32:59 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-25 22:32:59 -0500
commitabfea518adf24b5f2a6245ba37e068bfe97152ce (patch)
tree509cb03dd7cdf2480de1bd05233e8a9cd7481a16 /std
parent99617c04505fc3921cecaf6fa204229a2a1f3544 (diff)
seem to have fully fixed packages
Diffstat (limited to 'std')
-rw-r--r--std/arr.toc18
1 files changed, 7 insertions, 11 deletions
diff --git a/std/arr.toc b/std/arr.toc
index 0e81f3a..12d44f5 100644
--- a/std/arr.toc
+++ b/std/arr.toc
@@ -4,24 +4,20 @@ pkg "arr";
#export Arr ::= fn (t :: Type) Type {
struct {
data : []t;
- len, cap : int;
+ cap : int;
}
};
#export arr_add ::= fn(t ::=, a : &Arr(t), x : t) {
- if a.len >= a.cap {
+ if a.data.len >= a.cap {
a.cap = a.cap * 2 + 2;
new_data := new(t, a.cap);
- for i := 0..a.len-1 {
+ new_data.len = a.data.len;
+ for i := 0..a.data.len-1 {
new_data[i] = a.data[i];
}
a.data = new_data;
}
- a.data[a.len] = x;
- a.len += 1;
-};
-
-#export arr_foreach ::= fn(t ::=, a : Arr(t), f : fn(&t)) {
- for i := 0..a.len-1 {
- f(&a.data[i]);
- }
+ a.data[a.data.len] = x;
+ a.data.len += 1;
};
+#export arr_len ::= fn(t ::=, a : Arr(t)) int { a.data.len };