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