Previous Next Contents

24. Some Useful List Functions

These functions all manipulate lists.

> (append '(1 2 3) '(4 5 6))    ;concatenate lists
(1 2 3 4 5 6)
> (reverse '(1 2 3))            ;reverse the elements of a list
(3 2 1)
> (member 'a '(b d a c))        ;set membership -- returns the first tail
(A C)                           ;whose car is the desired element
> (find 'a '(b d a c))          ;another way to do set membership
> (find '(a b) '((a d) (a d e) (a b d e) ()) :test #'subsetp)
(A B D E)                       ;find is more flexible though
> (subsetp '(a b) '(a d e))     ;set containment
> (intersection '(a b c) '(b))  ;set intersection
> (union '(a) '(b))             ;set union
(A B)
> (set-difference '(a b) '(a))  ;set difference

Subsetp, intersection, union, and set-difference all assume that each argument contains no duplicate elements -- (subsetp '(a a) '(a b b)) is allowed to fail, for example.

Find, subsetp, intersection, union, and set-difference can all take a :test keyword argument; by default, they all use eql.

Previous Next Contents