mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-06-24 20:30:28 +02:00
(partition): Change to a tail-recursive form.
This commit is contained in:
parent
cabc854555
commit
f6ff79c415
1 changed files with 8 additions and 7 deletions
|
@ -747,13 +747,14 @@
|
|||
(filiter pred list '())))
|
||||
|
||||
(define (partition pred list)
|
||||
(if (null? list)
|
||||
(values '() '())
|
||||
(if (pred (car list))
|
||||
(receive (in out) (partition pred (cdr list))
|
||||
(values (cons (car list) in) out))
|
||||
(receive (in out) (partition pred (cdr list))
|
||||
(values in (cons (car list) out))))))
|
||||
(let lp ((list list)
|
||||
(in '())
|
||||
(out '()))
|
||||
(if (null? list)
|
||||
(values (reverse! in) (reverse! out))
|
||||
(if (pred (car list))
|
||||
(lp (cdr list) (cons (car list) in) out)
|
||||
(lp (cdr list) in (cons (car list) out))))))
|
||||
|
||||
(define (remove pred list)
|
||||
(filter (lambda (x) (not (pred x))) list))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue