diff --git a/piclib/built-in.scm b/piclib/built-in.scm index d7070353..334b412d 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -21,3 +21,29 @@ (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)))