On 5/27/10 2:27 PM, Eli Barzilay wrote:
On May 26, Sam Tobin-Hochstadt wrote:
On Wed, May 26, 2010 at 3:54 PM, Eli Barzilay<e...@barzilay.org>  wrote:
On May 25, David Van Horn wrote:
Could the following make its way into unstable/list?  It adds
remf for symmetry with findf and memf.

Is there any reason for putting it in unstable?  It should not be
used outside of the racket tree.

I agree - I can't imagine that the interface to `remf' is likely to
change.

I missed the fact that this is removing only the first matching item
rather than all of them (which would make it the same as
`filter-not').  Are there any cases where this is useful?

Here's a patch that reverts adding remf to unstable and another that adds it to racket/list.

I think remf is useful since it is an abstraction of remove, remv, remq, etc., and including it is consistent with findf, memf, and assf.

David
From 30a93091b08fe4ae13c976dbbb50b5f0e68ca47a Mon Sep 17 00:00:00 2001
From: David Van Horn <dvanh...@ccs.neu.edu>
Date: Thu, 27 May 2010 11:56:00 -0400
Subject: [PATCH 1/2] Revert "Added remf to unstable/list."  It was misplaced in 
unstable.

This reverts commit c9d0bd10a1a617931b420471bb300253f84ae58a.

Signed-off-by: David Van Horn <dvanh...@ccs.neu.edu>
---
 collects/tests/unstable/list.rkt         |    9 ---------
 collects/unstable/list.rkt               |   10 ----------
 collects/unstable/scribblings/list.scrbl |   15 ---------------
 3 files changed, 0 insertions(+), 34 deletions(-)
 delete mode 100644 collects/tests/unstable/list.rkt

diff --git a/collects/tests/unstable/list.rkt b/collects/tests/unstable/list.rkt
deleted file mode 100644
index fedd410..0000000
--- a/collects/tests/unstable/list.rkt
+++ /dev/null
@@ -1,9 +0,0 @@
-#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 f8b964d..ab35a6f 100644
--- a/collects/unstable/list.rkt
+++ b/collects/unstable/list.rkt
@@ -112,13 +112,3 @@
 
 (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 3bc0a26..76509f6 100644
--- a/collects/unstable/scribblings/list.scrbl
+++ b/collects/unstable/scribblings/list.scrbl
@@ -103,18 +103,3 @@ 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))
-]
-
-}
-
-- 
1.7.1


From 8848e3adc9ef85723df3906b511757e826a2a468 Mon Sep 17 00:00:00 2001
From: David Van Horn <dvanh...@ccs.neu.edu>
Date: Thu, 27 May 2010 14:14:20 -0400
Subject: [PATCH 2/2] Added remf to racket/list.  Added documentation and tests.


Signed-off-by: David Van Horn <dvanh...@ccs.neu.edu>
---
 collects/racket/private/list.rkt           |    7 +++++++
 collects/scribblings/reference/pairs.scrbl |   10 ++++++++++
 collects/tests/racket/list.rktl            |    7 +++++++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/collects/racket/private/list.rkt b/collects/racket/private/list.rkt
index a943d07..89deecd 100644
--- a/collects/racket/private/list.rkt
+++ b/collects/racket/private/list.rkt
@@ -4,6 +4,7 @@
   (provide foldl
            foldr
 
+           remf
            remv
            remq
            remove
@@ -62,6 +63,12 @@
   (define (remv item list)
     (do-remove 'remv item list eqv?))
 
+  (define (remf pred list)
+    (unless (and (procedure? pred)
+                 (procedure-arity-includes? pred 1))
+      (raise-type-error 'remove "procedure (arity 2)" equal?))
+    (do-remove 'remf '_ list (lambda (_ y) (pred y))))
+
   (define (do-remove* who l r equal?)
     (unless (list? l)
       (raise-type-error who "list" l))
diff --git a/collects/scribblings/reference/pairs.scrbl 
b/collects/scribblings/reference/pairs.scrbl
index b6234dd..14283c9 100644
--- a/collects/scribblings/reference/pairs.scrbl
+++ b/collects/scribblings/reference/pairs.scrbl
@@ -443,6 +443,16 @@ Returns @scheme[(remove v lst eqv?)].
 ]}
 
 
+...@defproc[(remf [pred procedure?]
+               [lst list?])
+         list?]{
+Returns a list that is like @scheme[lst], omitting the first element
+of @scheme[lst] for which @scheme[pred] produces a true value.
+...@mz-examples[
+(remf negative? (list 1 -2 3 4 -5))
+]}
+
+
 @defproc[(remove* [v-lst list?] [lst list?] [proc procedure? equal?])
          list?]{
 
diff --git a/collects/tests/racket/list.rktl b/collects/tests/racket/list.rktl
index 23d21a6..35209a4 100644
--- a/collects/tests/racket/list.rktl
+++ b/collects/tests/racket/list.rktl
@@ -38,6 +38,13 @@
 (err/rt-test (let/ec k (foldr k 0 '(1 2) '(1 2 3))))
 (err/rt-test (let/ec k (foldr k 0 '(1 2) '(1 2) '(1 2 3))))
 
+(test '() remf positive? '())
+(test '(-2 3 4 -5) remf add1 '(1 -2 3 4 -5))
+(test '(-2 3 4 -5) remf positive? '(1 -2 3 4 -5))
+(test '(1 3 4 -5) remf even? '(1 -2 3 4 -5))
+(test '(1 -2 3 4 -5) remf (lambda (x) #f) '(1 -2 3 4 -5))
+(err/rt-test (remf cons '(1 2 3)))
+
 (test '(0 1 2) memf add1 '(0 1 2))
 (test '(2 (c 17)) memf number? '((a 1) (0 x) (1 w) 2 (c 17)))
 (test '("ok" (2 .7) c) memf string? '((a 0) (0 a) (1 w) "ok" (2 .7) c))
-- 
1.7.1

_________________________________________________
  For list-related administrative tasks:
  http://list.cs.brown.edu/mailman/listinfo/plt-dev

Reply via email to