implement some list functions in built-in.scm
This commit is contained in:
parent
6d606e84e0
commit
ec3a32ef24
|
@ -21,3 +21,29 @@
|
||||||
|
|
||||||
(define (list . args)
|
(define (list . args)
|
||||||
args)
|
args)
|
||||||
|
|
||||||
|
(define (list? obj)
|
||||||
|
(if (null? obj)
|
||||||
|
#t
|
||||||
|
(if (pair? obj)
|
||||||
|
(list? (cdr obj))
|
||||||
|
#f)))
|
||||||
|
|
||||||
|
(define (length list)
|
||||||
|
(if (null? list)
|
||||||
|
0
|
||||||
|
(+ 1 (length (cdr list)))))
|
||||||
|
|
||||||
|
(define (append xs ys)
|
||||||
|
(if (null? xs)
|
||||||
|
ys
|
||||||
|
(cons (car xs)
|
||||||
|
(append (cdr xs) ys))))
|
||||||
|
|
||||||
|
(define (list-tail list k)
|
||||||
|
(if (zero? k)
|
||||||
|
list
|
||||||
|
(list-tail (cdr list) (- k 1))))
|
||||||
|
|
||||||
|
(define (list-ref list k)
|
||||||
|
(car (list-tail list k)))
|
||||||
|
|
Loading…
Reference in New Issue