Next: Association Lists, Previous: Substitution of Expressions, Up: Lists

These functions perform operations on lists that represent sets of elements.

— Function: **cl-member**` item list ``&key :test :test-not :key`

This function searches

listfor an element matchingitem. If a match is found, it returns the cons cell whose car was the matching element. Otherwise, it returns`nil`

. Elements are compared by`eql`

by default; you can use the`:test`

,`:test-not`

, and`:key`

arguments to modify this behavior. See Sequences.The standard Emacs lisp function

`member`

uses`equal`

for comparisons; it is equivalent to`(cl-member`

itemlist`:test 'equal)`

. With no keyword arguments,`cl-member`

is equivalent to`memq`

.

The `cl-member-if`

and `cl-member-if-not`

functions
analogously search for elements that satisfy a given predicate.

— Function: **cl-tailp**` sublist list`

This function returns

`t`

ifsublistis a sublist oflist, i.e., ifsublistis`eql`

tolistor to any of its cdrs.

— Function: **cl-adjoin**` item list ``&key :test :test-not :key`

This function conses

itemonto the front oflist, like`(cons`

itemlist`)`

, but only ifitemis not already present on the list (as determined by`cl-member`

). If a`:key`

argument is specified, it is applied toitemas well as to the elements oflistduring the search, on the reasoning thatitemis “about” to become part of the list.

— Function: **cl-union**` list1 list2 ``&key :test :test-not :key`

This function combines two lists that represent sets of items, returning a list that represents the union of those two sets. The resulting list contains all items that appear in

list1orlist2, and no others. If an item appears in bothlist1andlist2it is copied only once. If an item is duplicated inlist1orlist2, it is undefined whether or not that duplication will survive in the result list. The order of elements in the result list is also undefined.

— Function: **cl-nunion**` list1 list2 ``&key :test :test-not :key`

This is a destructive version of

`cl-union`

; rather than copying, it tries to reuse the storage of the argument lists if possible.

— Function: **cl-intersection**` list1 list2 ``&key :test :test-not :key`

This function computes the intersection of the sets represented by

list1andlist2. It returns the list of items that appear in bothlist1andlist2.

— Function: **cl-nintersection**` list1 list2 ``&key :test :test-not :key`

This is a destructive version of

`cl-intersection`

. It tries to reuse storage oflist1rather than copying. It doesnotreuse the storage oflist2.

— Function: **cl-set-difference**` list1 list2 ``&key :test :test-not :key`

This function computes the “set difference” of

list1andlist2, i.e., the set of elements that appear inlist1butnotinlist2.

— Function: **cl-nset-difference**` list1 list2 ``&key :test :test-not :key`

This is a destructive

`cl-set-difference`

, which will try to reuselist1if possible.

— Function: **cl-set-exclusive-or**` list1 list2 ``&key :test :test-not :key`

This function computes the “set exclusive or” of

list1andlist2, i.e., the set of elements that appear in exactly one oflist1andlist2.