From 7b7bf727da3250907284368b98b0083a4b4e2386 Mon Sep 17 00:00:00 2001 From: mryouse Date: Sat, 3 Jun 2023 20:22:18 +0000 Subject: initial commit --- p99/p21.neb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 p99/p21.neb (limited to 'p99/p21.neb') diff --git a/p99/p21.neb b/p99/p21.neb new file mode 100644 index 0000000..8b465e9 --- /dev/null +++ b/p99/p21.neb @@ -0,0 +1,16 @@ +; P21 Insert an element at a given position into a list + +(def a (list "a" "b" "c" "d")) + +(func extend (lst1 lst2) + (reduce append lst2 lst1)) + +(func insert-at (item lst idx) + (extend + (slice lst 1 (- idx 1)) + (prepend (slice lst idx) item))) + ;(slice lst idx) + ;(append (slice lst 1 (- idx 1)) item))) + +(print (->string a)) +(print (->string (insert-at "f" a 2))) -- cgit v1.2.3