summaryrefslogtreecommitdiff
path: root/lib/std/slput.myr
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/slput.myr')
-rw-r--r--lib/std/slput.myr20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/std/slput.myr b/lib/std/slput.myr
new file mode 100644
index 0000000..88dc875
--- /dev/null
+++ b/lib/std/slput.myr
@@ -0,0 +1,20 @@
+use "types.use"
+use "alloc.use"
+use "die.use"
+
+pkg std =
+ generic slput : (sl : @a[:], idx : size, elt : @a -> @a[:])
+;;
+
+generic slput = {sl, idx, elt
+ var i
+ var len
+
+ len = sl.len
+ sl = slgrow(sl, sl.len + 1)
+ for i = len - 1; i >= idx; i--
+ sl[i + 1] = sl[i]
+ ;;
+ sl[idx] = elt
+ -> sl
+}