implement some list functions in built-in.scm

This commit is contained in:
Yuichi Nishiwaki 2013-10-29 02:50:26 +09:00
parent 6d606e84e0
commit ec3a32ef24
1 changed files with 26 additions and 0 deletions

View File

@ -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)))