File: LISP-tutorial-24.html

package info (click to toggle)
cmucl 20c-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 42,524 kB
  • sloc: lisp: 358,331; ansic: 28,385; asm: 3,777; sh: 1,236; makefile: 366; csh: 31
file content (52 lines) | stat: -rw-r--r-- 1,884 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<HTML>
<HEAD>
<TITLE>Common LISP Hints: Some Useful List Functions</TITLE>
</HEAD>
<BODY>
<A HREF="LISP-tutorial-23.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-25.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc24"><IMG SRC="toc.gif" ALT="Contents"></A>
<HR>
<H2><A NAME="s24">24. Some Useful List Functions</A></H2>

<P>These functions all manipulate lists.</P>
<P>
<BLOCKQUOTE><CODE>
<PRE>
&gt; (append '(1 2 3) '(4 5 6))    ;concatenate lists
(1 2 3 4 5 6)
&gt; (reverse '(1 2 3))            ;reverse the elements of a list
(3 2 1)
&gt; (member 'a '(b d a c))        ;set membership -- returns the first tail
(A C)                           ;whose car is the desired element
&gt; (find 'a '(b d a c))          ;another way to do set membership
A
&gt; (find '(a b) '((a d) (a d e) (a b d e) ()) :test #'subsetp)
(A B D E)                       ;find is more flexible though
&gt; (subsetp '(a b) '(a d e))     ;set containment
NIL
&gt; (intersection '(a b c) '(b))  ;set intersection
(B)
&gt; (union '(a) '(b))             ;set union
(A B)
&gt; (set-difference '(a b) '(a))  ;set difference
(B)
</PRE>
</CODE></BLOCKQUOTE>
</P>
<P><CODE>Subsetp</CODE>, <CODE>intersection</CODE>, <CODE>union</CODE>, and <CODE>set-difference</CODE>
all assume that each 
argument contains no duplicate elements -- <CODE>(subsetp '(a a) '(a b b))</CODE> is
allowed to fail, for example.</P>
<P><CODE>Find</CODE>, <CODE>subsetp</CODE>, <CODE>intersection</CODE>, <CODE>union</CODE>, and
<CODE>set-difference</CODE> can all take a
<CODE>:test</CODE> keyword argument; by default, they all use <CODE>eql</CODE>.</P>



<HR>
<A HREF="LISP-tutorial-23.html"><IMG SRC="prev.gif" ALT="Previous"></A>
<A HREF="LISP-tutorial-25.html"><IMG SRC="next.gif" ALT="Next"></A>
<A HREF="LISP-tutorial.html#toc24"><IMG SRC="toc.gif" ALT="Contents"></A>
</BODY>
</HTML>