add missing list functions
This commit is contained in:
parent
013060a06f
commit
787dae1fe5
|
@ -29,6 +29,14 @@
|
||||||
(list? (cdr obj))
|
(list? (cdr obj))
|
||||||
#f)))
|
#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)
|
(define (length list)
|
||||||
(if (null? list)
|
(if (null? list)
|
||||||
0
|
0
|
||||||
|
@ -40,6 +48,14 @@
|
||||||
(cons (car xs)
|
(cons (car xs)
|
||||||
(append (cdr xs) ys))))
|
(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)
|
(define (list-tail list k)
|
||||||
(if (zero? k)
|
(if (zero? k)
|
||||||
list
|
list
|
||||||
|
@ -47,3 +63,12 @@
|
||||||
|
|
||||||
(define (list-ref list k)
|
(define (list-ref list k)
|
||||||
(car (list-tail 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)))))
|
||||||
|
|
Loading…
Reference in New Issue