2013-10-28 13:50:12 -04:00
|
|
|
(define (zero? n)
|
|
|
|
(= n 0))
|
|
|
|
|
|
|
|
(define (positive? x)
|
|
|
|
(> x 0))
|
|
|
|
|
|
|
|
(define (negative? x)
|
|
|
|
(< x 0))
|
|
|
|
|
2013-10-27 05:38:55 -04:00
|
|
|
(define (caar p)
|
|
|
|
(car (car p)))
|
|
|
|
|
|
|
|
(define (cadr p)
|
|
|
|
(car (cdr p)))
|
|
|
|
|
|
|
|
(define (cdar p)
|
|
|
|
(cdr (car p)))
|
|
|
|
|
|
|
|
(define (cddr p)
|
|
|
|
(cdr (cdr p)))
|
|
|
|
|
|
|
|
(define (list . args)
|
|
|
|
args)
|
2013-10-28 13:50:26 -04:00
|
|
|
|
|
|
|
(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)))
|