50 lines
701 B
Scheme
50 lines
701 B
Scheme
(define (zero? n)
|
|
(= n 0))
|
|
|
|
(define (positive? x)
|
|
(> x 0))
|
|
|
|
(define (negative? x)
|
|
(< x 0))
|
|
|
|
(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)
|
|
|
|
(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)))
|