From ec3a32ef2485e1ffc905dc0080eba945ceed4349 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 29 Oct 2013 02:50:26 +0900 Subject: [PATCH] implement some list functions in built-in.scm --- piclib/built-in.scm | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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)))