add missing list functions

This commit is contained in:
Yuichi Nishiwaki 2013-10-29 16:39:04 +09:00
parent 013060a06f
commit 787dae1fe5
1 changed files with 25 additions and 0 deletions

View File

@ -29,6 +29,14 @@
(list? (cdr obj))
#f)))
(define (make-list k . args)
(if (null? args)
(make-list k #f)
(if (zero? k)
'()
(cons (car args)
(make-list (- k 1) (car args))))))
(define (length list)
(if (null? list)
0
@ -40,6 +48,14 @@
(cons (car xs)
(append (cdr xs) ys))))
(define (reverse list . args)
(if (null? args)
(reverse list '())
(if (null? list)
(car args)
(reverse (cdr list)
(cons (car list) (car args))))))
(define (list-tail list k)
(if (zero? k)
list
@ -47,3 +63,12 @@
(define (list-ref list k)
(car (list-tail list k)))
(define (list-set! list k obj)
(set-car! (list-tail list k) obj))
(define (list-copy obj)
(if (null? obj)
obj
(cons (car obj)
(list-copy (cdr obj)))))