From: smartnose
Subject: How to check whether a list has an item?
Date: 
Message-ID: <dda80c8e-c27a-4cf0-8071-9795e85308b2@d70g2000hsc.googlegroups.com>
I want to test whether a list (set) has an item. Is there any build-in
function like containp?

If not then I have to write a loop and scan every item which is quite
inefficient.

Or, is there any functions for quick sort or hash table something?

From: Jens Teich
Subject: Re: How to check whether a list has an item?
Date: 
Message-ID: <m2prmgezmj.fsf@jensteich.de>
smartnose <·········@gmail.com> writes:

> I want to test whether a list (set) has an item. Is there any build-in
> function like containp?

CL-USER> (member 42 (list 1 2 3))
NIL
CL-USER> (member 2 (list 1 2 3))
(2 3)

Jens
From: Pascal J. Bourguignon
Subject: Re: How to check whether a list has an item?
Date: 
Message-ID: <7cbpxx6hj2.fsf@pbourguignon.anevia.com>
smartnose <·········@gmail.com> writes:

> I want to test whether a list (set) has an item. Is there any build-in
> function like containp?
>
> If not then I have to write a loop and scan every item which is quite
> inefficient.


As mentionned, MEMBER or FIND (sometimes I use POSITION too) can
indicate whether a sequence contains an item.  But you should also
consider what it means.  By default, CL function will test for EQL
items.  But for most items, this is too strong a match.  

For example, if you want to find a string in a list, you may want to
use EQUAL (case sensitive), EQUALP (case insensitive), STRING= or
STRING-EQUALP (for string designers), or even some other custom
equality:

(member "bitsy"  '("itsy" "bitsy" "tiny" "weenie"))                        --> NIL
(member "bitsy"  '("itsy" "bitsy" "tiny" "weenie") :test (function equal)) --> true

(member "BITSY"  '("itsy" "bitsy" "tiny" "weenie") :test (function equal))   --> NIL
(member "BITSY"  '("itsy" "bitsy" "tiny" "weenie") :test (function equalp))  --> true

(member "BITSY"  '(itsy bitsy tiny weenie) :test (function equalp))   --> NIL
(member "BITSY"  '(itsy bitsy tiny weenie) :test (function string=))  --> true

(member "bitsy"  '(itsy bitsy tiny weenie) :test (function string=))       --> NIL
(member "bitsy"  '(itsy bitsy tiny weenie) :test (function string-equal))  --> true


> Or, is there any functions for quick sort or hash table something?

Yes, there exist such functions too.  What do you want to do?

-- 
__Pascal Bourguignon__
From: Drew Crampsie
Subject: Re: How to check whether a list has an item?
Date: 
Message-ID: <814095ad-94ac-4199-bb35-7646751735bc@c36g2000prc.googlegroups.com>
On Oct 4, 3:48 pm, smartnose <·········@gmail.com> wrote:
> I want to test whether a list (set) has an item. Is there any build-in
> function like containp?
>
> If not then I have to write a loop and scan every item which is quite
> inefficient.

The other answers are sufficient, but this bit about efficiency
bothers me. How do you expect a built in function to operate if not by
scanning every item and testing for some sort of equivalence?

Cheers,

drewc
>
> Or, is there any functions for quick sort or hash table something?