bigloo

 

Recipes

Page history last edited by OMouse 2 yrs ago

Recipes


 

Functional Programming-related

 

om-filter func lst

Works just like filter where the returned list consists of elements that failed to pass the test func. Additionally returns a list containing the elements tossed out.

(define (filter-keep func lst)
(let ((good '()) (bad '()))
(map (lambda (x)
(if (func x)
(set! bad (cons x bad))
(set! good (cons x good))))
lst)
(values (reverse good) (reverse bad))))

This version returns a list instead of multiple values. The filtered out list is the car of the returned list, and the elements tossed out are in the cadr of it.

(define (filter-keepl func lst)
(let ((good '()) (bad '()))
(map (lambda (x)
(if (func x)
(set! bad (cons x bad))
(set! good (cons x good))))
lst)
(list (reverse good) (reverse bad))))

Comments (0)

You don't have permission to comment on this page.