Make filter tail-recursive
This commit is contained in:
parent
7b1cc27b08
commit
5b215eb57a
|
@ -402,12 +402,8 @@
|
||||||
;; filter partition remove
|
;; filter partition remove
|
||||||
;; filter! partition! remove!
|
;; filter! partition! remove!
|
||||||
(define (filter pred list)
|
(define (filter pred list)
|
||||||
(if (null? list)
|
(let ((pcons (lambda (v acc) (if (pred v) (cons v acc) acc))))
|
||||||
'()
|
(reverse (fold pcons '() list))))
|
||||||
(if (pred (car list))
|
|
||||||
(cons (car list)
|
|
||||||
(filter pred (cdr list)))
|
|
||||||
(filter pred (cdr list)))))
|
|
||||||
|
|
||||||
(define (remove pred list)
|
(define (remove pred list)
|
||||||
(filter (lambda (x) (not (pred x))) list))
|
(filter (lambda (x) (not (pred x))) list))
|
||||||
|
|
Loading…
Reference in New Issue