| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Recipes

Page history last edited by PBworks 16 years, 7 months 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.