aboutsummaryrefslogtreecommitdiff
path: root/p99/p20.neb
diff options
context:
space:
mode:
Diffstat (limited to 'p99/p20.neb')
-rw-r--r--p99/p20.neb21
1 files changed, 21 insertions, 0 deletions
diff --git a/p99/p20.neb b/p99/p20.neb
new file mode 100644
index 0000000..06b5e60
--- /dev/null
+++ b/p99/p20.neb
@@ -0,0 +1,21 @@
+; P20 Remove the K'th element from a list.
+
+(def a (list "a" "b" "c" "d"))
+
+(func enumerate (lst)
+ (def ret (list))
+ (for-each lst
+ (redef ret (append ret (list (+ 1 (length ret)) _item_))))
+ ret)
+
+(func extend (lst1 lst2)
+ (reduce append lst2 lst1))
+
+; using slices
+(func remove-at-slice (lst idx)
+ (extend
+ (slice lst 1 (- idx 1))
+ (slice lst (+ idx 1))))
+
+(print (->string a))
+(print (->string (remove-at-slice a 2)))