Merge pull request #151 from koba-e964/master

Make filter tail-recursive
This commit is contained in:
Yuichi Nishiwaki 2014-06-26 19:33:26 +09:00
commit b77fac6ce1
1 changed files with 2 additions and 6 deletions

View File

@ -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))