aboutsummaryrefslogtreecommitdiff
path: root/p99/p21.neb
blob: 8b465e9074fb83719f4a8fc006121e5079f7da15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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)))