diff --git a/collects/tests/unstable/list.rkt b/collects/tests/unstable/list.rkt new file mode 100644 index 0000000000..fedd410ecc --- /dev/null +++ b/collects/tests/unstable/list.rkt @@ -0,0 +1,9 @@ +#lang scheme +(require unstable/list) +(require tests/eli-tester) +(test + (remf positive? '()) => '() + (remf positive? '(1 -2 3 4 -5)) => '(-2 3 4 -5) + (remf even? '(1 -2 3 4 -5)) => '(1 3 4 -5) + (remf (λ (x) #f) '(1 -2 3 4 -5)) => '(1 -2 3 4 -5)) + diff --git a/collects/unstable/list.rkt b/collects/unstable/list.rkt index ab35a6f026..f8b964d713 100644 --- a/collects/unstable/list.rkt +++ b/collects/unstable/list.rkt @@ -112,3 +112,13 @@ (provide map/values) +;; dvanhorn added: + +(define (remf f ls) + (cond [(null? ls) '()] + [(f (car ls)) (cdr ls)] + [else + (cons (car ls) + (remf f (cdr ls)))])) + +(provide/contract [remf (-> procedure? list? list?)]) diff --git a/collects/unstable/scribblings/list.scrbl b/collects/unstable/scribblings/list.scrbl index 76509f6291..3bc0a268fe 100644 --- a/collects/unstable/scribblings/list.scrbl +++ b/collects/unstable/scribblings/list.scrbl @@ -103,3 +103,18 @@ Produces lists of the respective values of @racket[f] applied to the elements in } +@addition{David Van Horn} + +@defproc[(remf [pred procedure?] + [lst list?]) + list?]{ +Returns a list that is like @racket[lst], omitting the first element of @racket[lst] +for which @racket[pred] produces a true value. + +@defexamples[ +#:eval the-eval +(remf negative? '(1 -2 3 4 -5)) +] + +} +