From 47f2726f4ce9bc20f29a84c30cd992585495e3c3 Mon Sep 17 00:00:00 2001 From: Kevin Ryde Date: Mon, 28 Jul 2003 23:43:51 +0000 Subject: [PATCH] (concatenate, concatenate!): Use scm_append and scm_append_x. --- srfi/srfi-1.c | 8 ++++++++ srfi/srfi-1.scm | 26 -------------------------- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/srfi/srfi-1.c b/srfi/srfi-1.c index 247e0c388..db35eb92b 100644 --- a/srfi/srfi-1.c +++ b/srfi/srfi-1.c @@ -63,6 +63,14 @@ equal_trampoline (SCM proc, SCM arg1, SCM arg2) } +/* scm_append and scm_append_x don't modify their list argument (only the + lists within that list in the case of scm_append_x), hence making them + suitable for direct use for concatentate. */ + +SCM_REGISTER_PROC (s_srfi1_concatenate, "concatenate", 1, 0, 0, scm_append); +SCM_REGISTER_PROC (s_srfi1_concatenate_x, "concatenate!", 1, 0, 0, scm_append_x); + + SCM_DEFINE (scm_srfi1_delete, "delete", 2, 1, 0, (SCM x, SCM lst, SCM pred), "Return a list containing the elements of @var{lst} but with\n" diff --git a/srfi/srfi-1.scm b/srfi/srfi-1.scm index 4b3b09160..507ebb3f6 100644 --- a/srfi/srfi-1.scm +++ b/srfi/srfi-1.scm @@ -427,32 +427,6 @@ #f (lp (cdr hare) (cdr tortoise) (+ l 2))))))))) -(define (concatenate l-o-l) - (let lp ((l l-o-l) (acc '())) - (if (null? l) - (reverse! acc) - (let lp0 ((ll (car l)) (acc acc)) - (if (null? ll) - (lp (cdr l) acc) - (lp0 (cdr ll) (cons (car ll) acc))))))) - -(define (concatenate! l-o-l) - (let lp0 ((l-o-l l-o-l)) - (cond - ((null? l-o-l) - '()) - ((null? (car l-o-l)) - (lp0 (cdr l-o-l))) - (else - (let ((result (car l-o-l)) (tail (last-pair (car l-o-l)))) - (let lp ((l (cdr l-o-l)) (ntail tail)) - (if (null? l) - result - (begin - (set-cdr! ntail (car l)) - (lp (cdr l) (last-pair ntail)))))))))) - - (define (append-reverse rev-head tail) (let lp ((l rev-head) (acc tail)) (if (null? l)