Added remf to unstable/list.

Signed-off-by: Jay McCarthy <jay@racket-lang.org>
This commit is contained in:
dvanhorn 2010-05-25 20:24:21 -04:00 committed by Jay McCarthy
parent 7c5973cb94
commit c9d0bd10a1
3 changed files with 34 additions and 0 deletions

View File

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

View File

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

View File

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