From: Slapstiq
Subject: Using Remove
Date: 
Message-ID: <sb_m4.1410$%5.144225@typhoon.nyroc.rr.com>
If I have a list how can I remove the negative numbers with using the
remove-if command?

Thank you.

From: Rainer Joswig
Subject: Re: Using Remove
Date: 
Message-ID: <rainer.joswig-9A1629.20345305022000@news.is-europe.net>
In article <····················@typhoon.nyroc.rr.com>, "Slapstiq" 
<········@rochester.rr.com> wrote:

> If I have a list how can I remove the negative numbers with using the
> remove-if command?

(remove-if #'minusp '(1 2 -3))

Rainer Joswig, ISION Internet AG, Harburger Schlossstra�e 1, 
21079 Hamburg, Germany, Tel: +49 40 77175 226
Email: ·············@ision.de , WWW: http://www.ision.de/
From: Pierre R. Mai
Subject: Re: Using Remove
Date: 
Message-ID: <87aelfv3gg.fsf@orion.dent.isdn.cs.tu-berlin.de>
"Slapstiq" <········@rochester.rr.com> writes:

> If I have a list how can I remove the negative numbers with using the
> remove-if command?

(remove-if #'minusp list)

OTOH I find remove-if-not (i.e. keep/filter) much more natural for
many tasks, since it states what you want to keep, which is indeed
what is often the real intention of the programmer:

(remove-if-not #'positive-p list)

Where positive-p might be defined as either

(defun positive-p (number)
  (or (zerop number) (plusp number)))

or 

(defun positive-p (number)
  (not (minusp number)))

You might want to think about whether negative zero (when working on
reals) should be positive or not, on implementations that support IEEE 
negative zero.

Regs, Pierre.

-- 
Pierre Mai <····@acm.org>         PGP and GPG keys at your nearest Keyserver
  "One smaller motivation which, in part, stems from altruism is Microsoft-
   bashing." [Microsoft memo, see http://www.opensource.org/halloween1.html]
From: Robert Monfera
Subject: Re: Using Remove
Date: 
Message-ID: <389D9B32.5308098B@fisec.com>
"Pierre R. Mai" wrote:

[...]
> OTOH I find remove-if-not (i.e. keep/filter) much more natural for
> many tasks, since it states what you want to keep, which is indeed
> what is often the real intention of the programmer:
>
> (remove-if-not #'positive-p list)
[...]

I agree, because it shows the intent more clearly both for the reader
and the compiler.  This function (and the destructive equivalent) is
deprecated though.  Maybe compilers (will) do some optimization that
does not make a #'(LAMBDA (x) (NOT (FOO X))) more expensive than
#'(LAMBDA (x) (FOO X)).

Maybe the name is the reason for deprecating them?  How about more
"elegant" ones?

REMOVE-WHEN
DELETE-WHEN
REMOVE-UNLESS
DELETE-UNLESS

Robert
From: Tor Henrik Hanken
Subject: Re: Using Remove
Date: 
Message-ID: <m3hffmgugd.fsf@mbone.ifi.uio.no>
[Robert Monfera]

| Maybe the name is the reason for deprecating them?  

according to Paul Graham in "On Lisp" p.62, the X-IF-NOT functions are
deprecated to encurage the use of COMPLEMENT to negate the predicate
on such occasions.
-- 
Best wishes,

Tor Henrik Hanken
From: Robert Monfera
Subject: Re: Using Remove
Date: 
Message-ID: <389DA61C.A39BBFE1@fisec.com>
Thanks for the info.  Now we can deprecate UNLESS :-)

Robert

Tor Henrik Hanken wrote:

> according to Paul Graham in "On Lisp" p.62, the X-IF-NOT functions
> are deprecated to encurage the use of COMPLEMENT to negate the
> predicate on such occasions.
From: Paul Dietz
Subject: Re: Using Remove
Date: 
Message-ID: <87n0dj$kf$1@schbbs.mot.com>
In article <··············@mbone.ifi.uio.no>,

> according to Paul Graham in "On Lisp" p.62, the X-IF-NOT functions are
> deprecated to encurage the use of COMPLEMENT to negate the predicate
> on such occasions.

There's little reason to avoid the REMOVE-IF-NOT function aside from
misplaced purity.  In Franz ACL it is faster than using COMPLEMENT,
and about as fast as manual #'(LAMBDA ... (NOT ...)).  It is no
harder to understand.  It is unlikely to be removed from the
language in the future (because the cost of retaining it is so
small.)  In the unlikely event it is removed, the user can add it
again with little effort.

You *could* use (LOOP FOR ... IN ... WHEN ... COLLECT ...).   :)

	Paul
From: Johan Kullstam
Subject: Re: Using Remove
Date: 
Message-ID: <m2900xantp.fsf@sophia.axel.nom>
Robert Monfera <·······@fisec.com> writes:

> "Pierre R. Mai" wrote:
> 
> [...]
> > OTOH I find remove-if-not (i.e. keep/filter) much more natural for
> > many tasks, since it states what you want to keep, which is indeed
> > what is often the real intention of the programmer:
> >
> > (remove-if-not #'positive-p list)
> [...]
> 
> I agree, because it shows the intent more clearly both for the reader
> and the compiler.  This function (and the destructive equivalent) is
> deprecated though.  Maybe compilers (will) do some optimization that
> does not make a #'(LAMBDA (x) (NOT (FOO X))) more expensive than
> #'(LAMBDA (x) (FOO X)).
> 
> Maybe the name is the reason for deprecating them?  How about more
> "elegant" ones?
> 
> REMOVE-WHEN
> DELETE-WHEN
> REMOVE-UNLESS
> DELETE-UNLESS

how about using the word "keep"?  i never liked the double-negative
feeling of REMOVE-IF-NOT.  i'd rather see

KEEP-WHEN

however, "keep" is only one word.  what would be the right words to
describe the destructive one?  i offer

NKEEP-WHEN

but the N- notation has always struck me as a bit weird too.  otoh
it's only a name and a rose...

-- 
J o h a n  K u l l s t a m
[········@ne.mediaone.net]
Don't Fear the Penguin!
From: Thomas A. Russ
Subject: Re: Using Remove
Date: 
Message-ID: <ymi1z6o1v7p.fsf@sevak.isi.edu>
You need to write a function that returns non-NIL when it encounters a
negative number.  Then pass that function as an argument to the
REMOVE-IF function.

Fully named:

  (defun negative-number-p (n)
     (< n 0))

  (remove-if #'negative-number-p list-of-numbers)


Shortcut method with anonymous test function:

  (remove-if #'(lambda (n) (< n 0)) list-of-numbers)


-- 
Thomas A. Russ,  USC/Information Sciences Institute          ···@isi.edu