From: Mark Carroll
Subject: Does this function exist?
Date: 
Message-ID: <gSj*NjH-n@news.chiark.greenend.org.uk>
I find myself wanting a function that removes all the elements of a
list that fail some predicate, e.g. something with the same behaviour
as:

>(defun select-elements (predicate xs)
  (let ((result))
    (dolist (x xs)
            (if (funcall predicate x)
                (push x result)))
    (reverse result)))
SELECT-ELEMENTS

>(select-elements #'symbolp '(1 2 a b 3 c 5 6))
(A B C)

Does something like this exist? I can't find any reference to such a
built-in form anywhere, but it seems such a fundamental list operation
and so Lispy that I can't help but wonder if I'm missing anything!

(Yes, I know I should probably write it with loop and collect and
whatever. (-:)

-- Mark

From: Lars Marius Garshol
Subject: Re: Does this function exist?
Date: 
Message-ID: <m31zbbk2h0.fsf@ifi.uio.no>
* Mark Carroll
|
| I find myself wanting a function that removes all the elements of a
| list that fail some predicate, 

You mean, something like:

> (setq tst '(1 2 3 4 5 6 7 8 9))
(1 2 3 4 5 6 7 8 9)
> (remove-if-not 'oddp tst)
(1 3 5 7 9)

--Lars M.
From: Andrew Cooke
Subject: Re: Does this function exist?
Date: 
Message-ID: <37F85960.7FB88D9B@andrewcooke.free-online.co.uk>
look at remove, remove-if and remove-if-not (:test key takes predicate)

Mark Carroll wrote:

> I find myself wanting a function that removes all the elements of a
> list that fail some predicate, e.g. something with the same behaviour
> as:
From: Rainer Joswig
Subject: Re: Does this function exist?
Date: 
Message-ID: <joswig-0410990925500001@194.163.195.67>
In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:

> I find myself wanting a function that removes all the elements of a
> list that fail some predicate

REMOVE-IF-NOT
From: Jason Trenouth
Subject: Re: Does this function exist?
Date: 
Message-ID: <oIz4N0QIBRdePA+UjMSD4U1QW8Vo@4ax.com>
On 04 Oct 1999 07:30:54 +0100 (BST), Mark Carroll
<·····@chiark.greenend.org.uk> wrote:

> I find myself wanting a function that removes all the elements of a
> list that fail some predicate, e.g. something with the same behaviour
> as:
> 
> >(defun select-elements (predicate xs)
>   (let ((result))
>     (dolist (x xs)
>             (if (funcall predicate x)
>                 (push x result)))
>     (reverse result)))
> SELECT-ELEMENTS
> 
> >(select-elements #'symbolp '(1 2 a b 3 c 5 6))
> (A B C)
> 
> Does something like this exist? I can't find any reference to such a
> built-in form anywhere, but it seems such a fundamental list operation
> and so Lispy that I can't help but wonder if I'm missing anything!

Others have mentioned REMOVE-IF-NOT, but both REMOVE-IF-NOT and DELETE-IF-NOT
are marked as deprecated in the CL HyperSpec:
http://www.harlequin.com/education/books/HyperSpec/Body/fun_removecm__elete-if-not.html#remove-if-not

The official route would appear to be:

	(remove-if (complement #'symbolp) '(1 2 a b 3 c 5 6))

__Jason
From: Mark Carroll
Subject: Re: Does this function exist?
Date: 
Message-ID: <nZf*yII-n@news.chiark.greenend.org.uk>
In article <····························@4ax.com>,
Jason Trenouth  <·····@harlequin.com> wrote:
(snip)
>Others have mentioned REMOVE-IF-NOT, but both REMOVE-IF-NOT and DELETE-IF-NOT
>are marked as deprecated in the CL HyperSpec:
>http://www.harlequin.com/education/books/HyperSpec/Body/fun_removecm__elete-if-not.html#remove-if-not
>
>The official route would appear to be:
>
>	(remove-if (complement #'symbolp) '(1 2 a b 3 c 5 6))

(and remove-if-not, as suggested elsewhere)

Thank you very much indeed! (-: (And also to everyone else who
replied.) How I missed finding this function I've no idea - I
appreciate the pointer to it. (-:

Lisp seems very much like UNIX in that once you've learned the names
of all the little commands that do simple things, you can do a lot.
It's just a case of getting good at finding the little commands you
think should exist!

-- Mark
From: Jason Trenouth
Subject: Re: Does this function exist?
Date: 
Message-ID: <s6b4N9ide+n5vfab8Pw4DfnBukKp@4ax.com>
On 04 Oct 1999 13:49:37 +0100 (BST), Mark Carroll
<·····@chiark.greenend.org.uk> wrote:

> In article <····························@4ax.com>,
> Jason Trenouth  <·····@harlequin.com> wrote:
> (snip)
> >Others have mentioned REMOVE-IF-NOT, but both REMOVE-IF-NOT and DELETE-IF-NOT
> >are marked as deprecated in the CL HyperSpec:
> >http://www.harlequin.com/education/books/HyperSpec/Body/fun_removecm__elete-if-not.html#remove-if-not
> >
> >The official route would appear to be:
> >
> >	(remove-if (complement #'symbolp) '(1 2 a b 3 c 5 6))
> 
> (and remove-if-not, as suggested elsewhere)

No.

__Jason
From: Mark Carroll
Subject: Re: Does this function exist?
Date: 
Message-ID: <KKq*4bJ-n@news.chiark.greenend.org.uk>
In article <····························@4ax.com>,
Jason Trenouth  <·····@harlequin.com> wrote:
>On 04 Oct 1999 13:49:37 +0100 (BST), Mark Carroll
><·····@chiark.greenend.org.uk> wrote:
(snip)
>> (and remove-if-not, as suggested elsewhere)
>
>No.

Doh - sorry - indeed.

-- Mark
From: Christopher R. Barry
Subject: Re: Does this function exist?
Date: 
Message-ID: <87ogefyrxp.fsf@2xtreme.net>
Mark Carroll <·····@chiark.greenend.org.uk> writes:

> It's just a case of getting good at finding the little commands you
> think should exist!

Since you wanted to work with lists -- which are sequences -- you
should have begun your search by going to Chapter 17 (Sequences) in
the HyperSpec, where you would have found these functions in 17.3 (The
Sequences Dictionary).

Christopher
From: Mark Carroll
Subject: Re: Does this function exist?
Date: 
Message-ID: <sdF*VQS-n@news.chiark.greenend.org.uk>
In article <··············@2xtreme.net>,
Christopher R. Barry <······@2xtreme.net> wrote:
>Mark Carroll <·····@chiark.greenend.org.uk> writes:
>
>> It's just a case of getting good at finding the little commands you
>> think should exist!
>
>Since you wanted to work with lists -- which are sequences -- you
>should have begun your search by going to Chapter 17 (Sequences) in
>the HyperSpec, where you would have found these functions in 17.3 (The
>Sequences Dictionary).

Heh - although things like LIST-LENGTH are in chapter 14! Yes, I
normally would have found it - quite how I missed it this time I don't
know. Thanks. (-:

-- Mark
From: Rainer Joswig
Subject: Re: Does this function exist?
Date: 
Message-ID: <joswig-0610991709210001@pbg3.lavielle.com>
In article <·········@news.chiark.greenend.org.uk>, Mark Carroll <·····@chiark.greenend.org.uk> wrote:

> Lisp seems very much like UNIX in that once you've learned the names
> of all the little commands that do simple things, you can do a lot.
> It's just a case of getting good at finding the little commands you
> think should exist!

Well, Unix doesn't even give you a chance to guess names.

It would be a good think though to have a classification
of the various functionality (classes, functions, macros, ...)
in a Lisp system. This would for example make browsing around
a bit simpler.

Smalltalk has the idea of a "category" for this. I guess,
this would be a good idea for a Lisp system, too. Kind
of an ontology + knowledge base for Lisp operators.
From: William Deakin
Subject: Re: Does this function exist?
Date: 
Message-ID: <37FC9737.825EC881@pindar.com>
Rainer Joswig wrote:

> Well, Unix doesn't even give you a chance to guess names.

Yes it does, that's what shell completion is for ;)

Best Regards,

:) will
From: Duane Rettig
Subject: Re: Does this function exist?
Date: 
Message-ID: <4ogebjlqg.fsf@beta.franz.com>
William Deakin <·····@pindar.com> writes:

> Rainer Joswig wrote:
> 
> > Well, Unix doesn't even give you a chance to guess names.
> 
> Yes it does, that's what shell completion is for ;)

Nah.  Use "man -k" (or apropos(1), if available).  Shell completion
helps in the case of foo<something>, but not for <something>foo.

Of course, it depends on whether we're talking about commands or
files, anyway.

-- 
Duane Rettig          Franz Inc.            http://www.franz.com/ (www)
1995 University Ave Suite 275  Berkeley, CA 94704
Phone: (510) 548-3600; FAX: (510) 548-8253   ·····@Franz.COM (internet)
From: Rainer Joswig
Subject: Re: Does this function exist?
Date: 
Message-ID: <joswig-0710991716080001@pbg3.lavielle.com>
In article <·················@pindar.com>, ········@pindar.com wrote:

> Rainer Joswig wrote:
> 
> > Well, Unix doesn't even give you a chance to guess names.
> 
> Yes it does, that's what shell completion is for ;)

How do you guess names like "gsscred", "prtvtoc" or "zic"?
From: Quentin Deakin
Subject: Re: Does this function exist?
Date: 
Message-ID: <7tqmin$job$1@epos.tesco.net>
Rainer Joswig wrote in message ...
>In article <·················@pindar.com>, ········@pindar.com wrote:
>
>> Rainer Joswig wrote:
>>
>> > Well, Unix doesn't even give you a chance to guess names.
>>
>> Yes it does, that's what shell completion is for ;)
>
>How do you guess names like "gsscred", "prtvtoc" or "zic"?

Alright, already, that was a smart answer.  Duane Rettig is correct, the
best thing to do is apropos.

If not, the I find something like
find <man-path> -name \*.gz -o -name \*.Z | xargs findstuff <something to do
with what I'm looking for> $1

Where man-path is something like /usr/man or /usr/local/man. Or in fact one
then the other. And findstuff is an script with execute permissions
consisting of something like

#!/bin/bash
zcat $2 | grep -ni $1 $2

or what ever. *that* is how I found out about zic (for example).

Best Regards,

:) will