From 787dae1fe592718b592e93b48d19d292f7917eb6 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Tue, 29 Oct 2013 16:39:04 +0900 Subject: [PATCH] add missing list functions --- piclib/built-in.scm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/piclib/built-in.scm b/piclib/built-in.scm index 334b412d..7533843e 100644 --- a/piclib/built-in.scm +++ b/piclib/built-in.scm @@ -29,6 +29,14 @@ (list? (cdr obj)) #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) (if (null? list) 0 @@ -40,6 +48,14 @@ (cons (car xs) (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) (if (zero? k) list @@ -47,3 +63,12 @@ (define (list-ref 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)))))