mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-10 14:00:21 +02:00
(concatenate, concatenate!): Use scm_append and scm_append_x.
This commit is contained in:
parent
603707f49b
commit
47f2726f4c
2 changed files with 8 additions and 26 deletions
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue