Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
remove-if-not, still allowed or considered to be verbotten?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  20 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Yves S. Garret  
View profile  
 More options Sep 18 2012, 1:45 pm
Newsgroups: comp.lang.lisp
From: "Yves S. Garret" <yoursurrogate...@gmail.com>
Date: Tue, 18 Sep 2012 10:45:38 -0700 (PDT)
Local: Tues, Sep 18 2012 1:45 pm
Subject: remove-if-not, still allowed or considered to be verbotten?
I'm going through PCL and now on Chapter 11:

http://gigamonkeys.com/book/collections.html

I found this portion:

"
According to the language standard, the -IF-NOT variants are deprecated. However, that deprecation is generally considered to have itself been ill-advised. If the standard is ever revised, it's more likely the deprecation will be removed than the -IF-NOT functions. For one thing, the REMOVE-IF-NOT variant is probably used more often than REMOVE-IF. Despite its negative-sounding name, REMOVE-IF-NOT is actually the positive variant--it returns the elements that do satisfy the predicate.
"

Is there a general consensus (preference, understanding, whatever) on whether -if-not is preferred or -if, but having the method that you're using wrapped in (complement #'function-test)?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal Costanza  
View profile  
 More options Sep 18 2012, 1:59 pm
Newsgroups: comp.lang.lisp
From: Pascal Costanza <p...@p-cos.net>
Date: Tue, 18 Sep 2012 19:59:43 +0200
Local: Tues, Sep 18 2012 1:59 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
On 18/09/2012 19:45, Yves S. Garret wrote:

> I'm going through PCL and now on Chapter 11:

> http://gigamonkeys.com/book/collections.html

> I found this portion:

> "
> According to the language standard, the -IF-NOT variants are deprecated. However, that deprecation is generally considered to have itself been ill-advised. If the standard is ever revised, it's more likely the deprecation will be removed than the -IF-NOT functions. For one thing, the REMOVE-IF-NOT variant is probably used more often than REMOVE-IF. Despite its negative-sounding name, REMOVE-IF-NOT is actually the positive variant--it returns the elements that do satisfy the predicate.
> "

> Is there a general consensus (preference, understanding, whatever) on whether -if-not is preferred or -if, but having the method that you're using wrapped in (complement #'function-test)?

REMOVE-IF-NOT is not particularly hard to understand, and its semantics
are not problematic in any way. It's also fewer characters to type than
the alternatives, so it's definitely fine to use it.

COMPLEMENT is funky, IMO. But hey, if prefer that, go ahead...

Pascal

--
My website: http://p-cos.net
Common Lisp Document Repository: http://cdr.eurolisp.org
Closer to MOP & ContextL: http://common-lisp.net/project/closer/
The views expressed are my own, and not those of my employer.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Yves S. Garret  
View profile  
 More options Sep 18 2012, 2:05 pm
Newsgroups: comp.lang.lisp
From: "Yves S. Garret" <yoursurrogate...@gmail.com>
Date: Tue, 18 Sep 2012 11:05:01 -0700 (PDT)
Local: Tues, Sep 18 2012 2:05 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

I don't have an issue with how to use it, merely wondering if it's something that should be avoided or actively used :-) .

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RG  
View profile  
 More options Sep 18 2012, 2:26 pm
Newsgroups: comp.lang.lisp
From: RG <rNOSPA...@flownet.com>
Date: Tue, 18 Sep 2012 11:26:26 -0700
Local: Tues, Sep 18 2012 2:26 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
In article <3b11dd1a-baad-4567-8081-b72bd9526ab3@googlegroups.com>,
 "Yves S. Garret" <yoursurrogate...@gmail.com> wrote:

It doesn't matter because:

1.  The standard will never be revised

2.  Even if the standard were revised, adding remove-if-not at the used
level is an elementary exercise.

So if you like remove-if-not, use it.  Otherwise don't.

Personally, I think the right name for REMOVE-IF-NOT is FILTER.

You might also want to consider using list comprehensions and iterators:

http://blog.rongarret.info/2008/02/joy-of-iterators.html

rg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Sep 18 2012, 2:38 pm
Newsgroups: comp.lang.lisp
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Tue, 18 Sep 2012 20:38:10 +0200
Local: Tues, Sep 18 2012 2:38 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
"Yves S. Garret" <yoursurrogate...@gmail.com> writes:

> I don't have an issue with how to use it, merely wondering if it's
> something that should be avoided or actively used :-) .

No, you can use either

          (remove-if-not predicate sequence)
or        
          (remove-if (complement predicate) sequence)

Notice that often predicate is a lambda form, and therefore you can
invert the condition returned by the predicate. Instead of:

         (remove-if-not (lambda (x) (or (zerop (mod x 3)) (zerop (mod x 5))))
                        sequence)

you can write:

         (remove-if (lambda (x) (and (/= 0 (mod x 3)) (/= 0 (mod x 5))))
                    sequence)

But notice also that instead of using lambda forms, you can collect a
library of utility high order functions such as:

(defun there-is (&rest funs)
  (lambda (&rest args)
     (every (lambda (fun) (apply fun args)) funs)))

(defun rcurry (fun &rest right-args)
   (lambda (&rest left-args)
      (apply fun (append left-args right-args))))

(defun compose (fun &rest funs)
  (if funs
     (lambda (&rest args)
        (funcall fun (apply (apply (function compose) funs) args)))
     fun))

(defun iota (max &key (start 0) (step 1))
  (loop for i :from start :to max :by step collect i))

;; Some of them are already in alexandria or some other libraries.

So that you can write it, without using any variable or parameter:

(remove-if (complement (there-is (compose (function zerop) (rcurry (function mod) 3))
                                 (compose (function zerop) (rcurry (function mod) 5))))
                    (iota 40))
--> (0 15 30)

(remove-if-not (there-is (compose (function zerop) (rcurry (function mod) 3))
                         (compose (function zerop) (rcurry (function mod) 5)))
        (iota 40))
--> (0 15 30)

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RG  
View profile  
 More options Sep 18 2012, 3:31 pm
Newsgroups: comp.lang.lisp
From: RG <rNOSPA...@flownet.com>
Date: Tue, 18 Sep 2012 12:31:36 -0700
Local: Tues, Sep 18 2012 3:31 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
In article <rNOSPAMon-21ACED.11262518092...@news.albasani.net>,

That should be "user" not "used."


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Mandl  
View profile  
 More options Sep 18 2012, 3:48 pm
Newsgroups: comp.lang.lisp
From: Stefan Mandl <StefanMa...@web.de>
Date: Tue, 18 Sep 2012 21:48:38 +0200
Local: Tues, Sep 18 2012 3:48 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

RG <rNOSPA...@flownet.com> writes:
> Personally, I think the right name for REMOVE-IF-NOT is FILTER.

Me too.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Teemu Likonen  
View profile  
 More options Sep 19 2012, 12:29 am
Newsgroups: comp.lang.lisp
From: Teemu Likonen <tliko...@iki.fi>
Date: Wed, 19 Sep 2012 07:29:17 +0300
Local: Wed, Sep 19 2012 12:29 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
RG [2012-09-18 11:26:26 -0700] wrote:

> Personally, I think the right name for REMOVE-IF-NOT is FILTER.

Personally I wouldn't know if FILTER means REMOVE-IF or REMOVE-IF-NOT.

    (filter #'numberp sequence)

Does that filter numbers out or just leave numbers?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Sep 19 2012, 1:06 am
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@kylheku.com>
Date: Wed, 19 Sep 2012 05:06:33 +0000 (UTC)
Local: Wed, Sep 19 2012 1:06 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
On 2012-09-19, Teemu Likonen <tliko...@iki.fi> wrote:

> RG [2012-09-18 11:26:26 -0700] wrote:

>> Personally, I think the right name for REMOVE-IF-NOT is FILTER.

> Personally I wouldn't know if FILTER means REMOVE-IF or REMOVE-IF-NOT.

Those are not the only two possible meanings. Filter could mean retain,
remove, but it has also come to mean to alter through an arbitrary function.

>     (filter #'numberp sequence)

> Does that filter numbers out or just leave numbers?

Or is it a new name for (mapcar #'numberp sequence), like
first and rest for car and cdr?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Barry Margolin  
View profile  
 More options Sep 19 2012, 1:27 am
Newsgroups: comp.lang.lisp
From: Barry Margolin <bar...@alum.mit.edu>
Date: Wed, 19 Sep 2012 01:27:15 -0400
Local: Wed, Sep 19 2012 1:27 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
In article <3b11dd1a-baad-4567-8081-b72bd9526ab3@googlegroups.com>,
 "Yves S. Garret" <yoursurrogate...@gmail.com> wrote:

> I don't have an issue with how to use it, merely wondering if it's something
> that should be avoided or actively used :-)

Since the chance of the Common Lisp standard ever being revised is
epsilon, you can do whatever you want.

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Elias Mårtenson  
View profile  
 More options Sep 19 2012, 1:54 am
Newsgroups: comp.lang.lisp
From: Elias Mårtenson <loke...@gmail.com>
Date: Tue, 18 Sep 2012 22:54:28 -0700 (PDT)
Local: Wed, Sep 19 2012 1:54 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

On Wednesday, 19 September 2012 12:29:20 UTC+8, Teemu Likonen  wrote:
> RG [2012-09-18 11:26:26 -0700] wrote:

> > Personally, I think the right name for REMOVE-IF-NOT is FILTER.

> Personally I wouldn't know if FILTER means REMOVE-IF or REMOVE-IF-NOT.

If we're talking about a hypothetical rename that will never happen, here's another suggestion:

KEEP-IF


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RG  
View profile  
 More options Sep 19 2012, 2:35 am
Newsgroups: comp.lang.lisp
From: RG <rNOSPA...@flownet.com>
Date: Tue, 18 Sep 2012 23:35:56 -0700
Local: Wed, Sep 19 2012 2:35 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
In article <dd3053ee-17fa-42cc-beac-590d45349768@googlegroups.com>,
 Elias Mårtenson <loke...@gmail.com> wrote:

> On Wednesday, 19 September 2012 12:29:20 UTC+8, Teemu Likonen  wrote:
> > RG [2012-09-18 11:26:26 -0700] wrote:

> > > Personally, I think the right name for REMOVE-IF-NOT is FILTER.

> > Personally I wouldn't know if FILTER means REMOVE-IF or REMOVE-IF-NOT.

> If we're talking about a hypothetical rename that will never happen, here's
> another suggestion:

> KEEP-IF

I like FILTER not because its meaning is self-evident but because it's a
universal convention in the functional programming world that filter
means remove-if-not.  But KEEP-IF is good to.

Or we could go with DONT-REMOVE-IF-NOT-NULL.

rg


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Pascal J. Bourguignon  
View profile  
 More options Sep 19 2012, 3:06 am
Newsgroups: comp.lang.lisp
From: "Pascal J. Bourguignon" <p...@informatimago.com>
Date: Wed, 19 Sep 2012 09:06:27 +0200
Local: Wed, Sep 19 2012 3:06 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

RG <rNOSPA...@flownet.com> writes:
> I like FILTER not because its meaning is self-evident but because it's a
> universal convention in the functional programming world that filter
> means remove-if-not.  But KEEP-IF is good to.

Then an even better word than FILTER would be: DEMETER-IN-THE-FIELDS

http://en.memory-alpha.org/wiki/Tamarian_language

--
__Pascal Bourguignon__                     http://www.informatimago.com/
A bad day in () is better than a good day in {}.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Sep 19 2012, 3:15 am
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@kylheku.com>
Date: Wed, 19 Sep 2012 07:15:42 +0000 (UTC)
Local: Wed, Sep 19 2012 3:15 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
On 2012-09-19, Elias Mårtenson <loke...@gmail.com> wrote:

> On Wednesday, 19 September 2012 12:29:20 UTC+8, Teemu Likonen  wrote:
>> RG [2012-09-18 11:26:26 -0700] wrote:

>> > Personally, I think the right name for REMOVE-IF-NOT is FILTER.

>> Personally I wouldn't know if FILTER means REMOVE-IF or REMOVE-IF-NOT.

> If we're talking about a hypothetical rename that will never happen, here's
> another suggestion:

> KEEP-IF

Ah yes, nice name. I put such a function into TXR Lisp, as well as a lazy
workalike called keep-if*.

(The : symbol in lambda lists denotes the start of optional parameters.
A rest param is introduced by a consing dot.)

   Functions remove-if, keep-if, remove-if* and keep-if*
       Syntax:

                (remove-if <predicate-function> <list> : <key-function>)
                (keep-if <predicate-function> <list> : <key-function>)
                (remove-if* <predicate-function> <list> : <key-function>)
                (keep-if* <predicate-function> <list> : <key-function>)

       Description

              The  remove-if function produces a list whose contents are those
              of <list> but with those elements removed which satisfy  <predi-
              cate-function>.   Those elements which are not removed appear in
              the same order.  The result list may share substructure with the
              input list, and may even be the same list object if no items are
              removed.

              The optional <key-function> specifies how each element from  the
              <list> is transformed to an argument to <predicate-function>. If
              this argument is omitted or specified as nil, then the predicate
              function  is  applied to the elements directly, a behavior which
              is identical to <key-function> being (fun identity).

              The keep-if function is exactly like remove-if, except the sense
              of the predicate is inverted. The function keep-if retains those
              items which  remove-if  will  delete,  and  removes  those  that
              remove-if will preserve.

              The  remove-if* and keep-if* are like remove-if and keep-if, but
              produce lazy lists.

       Examples:

                ;; remove any element numerically equal to 3.
                (remove-if (op = 3) '(1 2 3 4 3.0 5)) -> (1 2 4 5)

                ;; remove those pairs whose first element begins with "abc"
                [remove-if (op equal [@1 0..3] "abc")
                           '(("abcd" 4) ("defg" 5))
                           car]
                -> (("defg 5))

                ;; equivalent, without key function
                (remove-if (op equal [(car @1) 0..3] "abc")
                           '(("abcd" 4) ("defg" 5)))
                -> (("defg 5))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kaz Kylheku  
View profile  
 More options Sep 19 2012, 3:27 am
Newsgroups: comp.lang.lisp
From: Kaz Kylheku <k...@kylheku.com>
Date: Wed, 19 Sep 2012 07:27:23 +0000 (UTC)
Local: Wed, Sep 19 2012 3:27 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?
On 2012-09-19, RG <rNOSPA...@flownet.com> wrote:

Haha, check this.

In the GNU Make language (which I hardly need point out is more popular and
widely used than any functional language) you have these:

  $(filter pattern...,text)
      Returns all whitespace-separated words in text that do match any
      of the pattern words, removing any words that do not match. The
      patterns are written using ‘%’, just like the patterns used in
      the patsubst function above.

  [ snip examples ]

  $(filter-out pattern...,text)
      Returns all whitespace-separated words in text that do not match
      any of the pattern words, removing the words that do match one or
      more. This is the exact opposite of the filter function.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Oct 17 2012, 7:45 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 17 Oct 2012 11:44:54 GMT
Local: Wed, Oct 17 2012 7:44 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

Instead of using DARPA CL, let's use a Lispy language.

Racket:

: (filter even? '(0 1 2 3 4))
'(0 2 4)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Oct 17 2012, 8:57 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 17 Oct 2012 12:56:56 GMT
Local: Wed, Oct 17 2012 8:56 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

Excellent suggestion, much more in keeping with the
DARPA CL philosophy.

"Do you not never read no newspapers?" (Midnight Manhunt)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Oct 17 2012, 9:46 am
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 17 Oct 2012 13:45:20 GMT
Local: Wed, Oct 17 2012 9:45 am
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

Instead of DARPA CL, let's use a Lispy language.

Racket:

(define (divisors? xs x)
  (andmap (compose zero? (curry modulo x)) xs))
(filter (curry divisors? '(3 5)) (build-list 40 values))
--> '(0 15 30)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Oct 17 2012, 3:21 pm
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 17 Oct 2012 19:21:01 GMT
Local: Wed, Oct 17 2012 3:21 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

Pascal J. Bourguignon wrote:
> RG <rNOSPA...@flownet.com> writes:

> > I like FILTER not because its meaning is self-evident but because it's a
> > universal convention in the functional programming world that filter
> > means remove-if-not.  But KEEP-IF is good to.

> Then an even better word than FILTER would be: DEMETER-IN-THE-FIELDS

Another example of the "thinking" that has made
DARPA CL the ugliest, clunkiest language that
the world has ever known.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
WJ  
View profile  
 More options Jan 24, 5:05 pm
Newsgroups: comp.lang.lisp
From: "WJ" <w_a_x_...@yahoo.com>
Date: 24 Jan 2013 22:05:33 GMT
Local: Thurs, Jan 24 2013 5:05 pm
Subject: Re: remove-if-not, still allowed or considered to be verbotten?

Racket:

  > (filter (curry divisors? '(3 5)) (range 40))
  '(0 15 30)

Bigloo:

(define-macro ($ . exprs) `(lambda (%) ,exprs))

(define (divisors? xs x)
  (every ($ zero? (remainder x %)) xs))

(filter ($ divisors? '(3 5) %) (iota 40))
 ==> (0 15 30)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »