Brian Campbell <lambda3@hotmail.com> wrote:
+---------------
| Mohap wrote:
| > What is the function to find out if an element is contained in a list?
|
| member?. It actually returns the item if it finds it, #f if not, since
| any value is a true value.
+---------------
Correction: "member?" returns the *pair* whose car contains the item,
or equivalently, returns the tail of the list starting with the first
item which matches. This distinction is important, since it allows
you to search for #f and still tell unambiguously whether it was in
the list or not:
> (member #f '(1 2 #f 3 4 5))
(#f 3 4 5)
> (member #f '(1 2 3 4 5 #f))
(#f)
> (member #f '(1 2 3 4 5))
#f
>
And since "member?" will never return the empty list,
you can safely & unambiguously search for the empty list:
> (member '() '(1 2 () 3 4 5))
(() 3 4 5)
> (member '() '(1 2 3 4 5 ()))
(())
> (member '() '())
#f
>
-Rob
-----
Rob Warnock, 31-2-510 rpw3@sgi.com
Network Engineering http://reality.sgi.com/rpw3/
Silicon Graphics, Inc. Phone: 650-933-1673
1600 Amphitheatre Pkwy. PP-ASEL-IA
Mountain View, CA 94043