Add possibly useful utility procedures

This commit is contained in:
Oliver Payne 2024-01-30 18:01:24 +00:00
parent 6529021476
commit 3632855fe5
1 changed files with 19 additions and 1 deletions

View File

@ -31,5 +31,23 @@
(if (null? l) true
(if (f (car l))
true
false)))))
false)))
(define (length l)
(if (null? l)
0
(+ 1 (length (cdr l)))))
(define (list-ref list k)
(if (= k 0)
(car list)
(list-ref (cdr list) (- k 1))))
;; Remove the kth element from list
(define (remove list k)
(if (= k 0)
(cdr list)
(cons (car list)
(remove (cdr list) (- k 1)))))
))