1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-22 19:44:10 +02:00

srfi-1 append-reverse: move from C to Scheme

* libguile/srfi-1.c (scm_srfi1_append_reverse): delete.
* libguile/srfi-1.h (scm_srfi1_append_reverse): delete.
* module/srfi/srfi-1.scm: add append-reverse.
This commit is contained in:
Rob Browning 2024-07-17 02:55:16 -05:00
parent c62d2962d4
commit 17281519df
3 changed files with 17 additions and 26 deletions

View file

@ -464,6 +464,23 @@ of arguments a function takes, which the @code{apply} might exceed. In
Guile there is no such limit."
(apply append! lists))
(define (append-reverse rev-head tail)
"Reverse @var{rev-head}, append @var{tail} to it, and return the
result. This is equivalent to @code{(append (reverse @var{rev-head})
@var{tail})}, but its implementation is more efficient.
@example
(append-reverse '(1 2 3) '(4 5 6)) @result{} (3 2 1 4 5 6)
@end example"
(let lp ((rh rev-head)
(result tail))
(if (pair? rh)
(lp (cdr rh) (cons (car rh) result))
(begin
(unless (null? rh)
(wrong-type-arg 'append-reverse rev-head))
result))))
(define (zip clist1 . rest)
(let lp ((l (cons clist1 rest)) (acc '()))
(if (any null? l)