aboutsummaryrefslogtreecommitdiff
path: root/std/prelude/arrays.pk
diff options
context:
space:
mode:
Diffstat (limited to 'std/prelude/arrays.pk')
-rw-r--r--std/prelude/arrays.pk24
1 files changed, 17 insertions, 7 deletions
diff --git a/std/prelude/arrays.pk b/std/prelude/arrays.pk
index 2e4a4d4..6f57865 100644
--- a/std/prelude/arrays.pk
+++ b/std/prelude/arrays.pk
@@ -1,20 +1,30 @@
-## std.arrays: The array[T, S] primitive and associated functions.
+## std.arrays: The array[T, size] primitive and associated functions.
## A stub module for documentation. Mostly compiler magic.
## Primitive fixed-size arrays. Their size is statically known at compile-time.
-pub type array[T, S: static[uint]]
+@[magic]
+pub type array[T, size: static uint]
## Array access. Returns None if i is out of range.
-pub func get[T, S: static[uint]](self: array[T, S], i: uint): T?
+@[magic]
+pub func get[T, size: static uint](self: lent array[T, size], i: uint): lent T?
+## Array access. Returns None if i is out of range.
+@[magic]
+pub func get[T, size: static uint](self: mut array[T, size], i: uint): mut T?
+
## Array mutation.
# todo: how do we detect range errors?
-pub func set[T, S: static[uint]](self: mut array[T, S], i: uint, val: T): T?
+@[magic]
+pub func set[T, size: static uint](self: mut array[T, size], i: uint, val: T): Success[IndexOutOfBounds]
+
## A helper function to get the length of an array.
## Known to the compiler, and computed at compile-time.
-pub func len[T, S: static[uint]](self: array[T, S], i: uint): T?
+@[inline]
+pub func len[T, size: static uint](self: lent array[T, size]): uint = size
-type ArrayIter[T, S: static[uint]] = struct
+type ArrayIter[T, size: static uint] = struct
+ ...
+pub func iter[T, size: static uint](self: array[T, size]): ArrayIter[T, S] =
...
-pub func iter[T, S: static[uint]](self: array[T, S]): ArrayIter[T, S]
# todo: Eq, PartialEq, Ord, PartialOrd