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

  • Want to get organized in 2022? Let Dokkio put your cloud files (Drive, Dropbox, and Slack and Gmail attachments) and documents (Google Docs, Sheets, and Notion) in order. Try Dokkio (from the makers of PBworks) for free. Available on the web, Mac, and Windows.

View
 

Recipes

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