aboutsummaryrefslogtreecommitdiff
path: root/p99/p20.neb
blob: 06b5e607782c8dea74d5ef811e16c3d30c5c17ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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)))