Previous: Modifying List Variables, Up: Sequence Functions [Index]
A sequence is normally considered an ordered collection. It can be considered as a set though.
These functions treat a list as an unordered mathematical set—they consider a value an element of a set if it appears in the list without reference to order.
To form the union of two sets, use ‘append’ and remove duplicates using ‘delete-dups’.
See the function ‘add-to-list’ for a way to add an element to a list stored in a variable and used as a set.
This function tests to see whether OBJECT is a member of LIST. If it is, ‘memq’ returns a list starting with the first occurrence of OBJECT. Otherwise, it returns ‘nil’. The letter ‘q’ in ‘memq’ says that it uses ‘eq’ to compare OBJECT against the elements of the list.
This function destructively removes all elements ‘eq’ to OBJECT from LIST, and returns the resulting list. The letter ‘q’ in ‘delq’ says that it uses ‘eq’ to compare OBJECT against the elements of the list, like ‘memq’ and ‘remq’. Typically, when you invoke ‘delq’, you should use the return value by assigning it to the variable which held the original list.
(setq flowers (delq 'rose flowers))
If you want to delete elements that are ‘equal’ to a given value, use ‘delete’.
This function returns a copy of LIST, with all elements removed which are ‘eq’ to OBJECT. The letter ‘q’ in ‘remq’ says that it uses ‘eq’ to compare OBJECT against the elements of ‘list’.
oThe function ‘memql’ tests to see whether OBJECT is a member of LIST, comparing members with OBJECT using ‘eql’, so floating-point elements are compared by value. If OBJECT is a member, ‘memql’ returns a list starting with its first occurrence in LIST. Otherwise, it returns ‘nil’.
The function ‘member’ tests to see whether OBJECT is a member of LIST, comparing members with OBJECT using ‘equal’. If OBJECT is a member, ‘member’ returns a list starting with its first occurrence in LIST. Otherwise, it returns ‘nil’.
This function removes all elements ‘equal’ to OBJECT from SEQUENCE, and returns the resulting sequence. As with ‘delq’, you should typically use the return value by assigning it to the variable which held the original list. If ‘sequence’ is a vector or string, ‘delete’ returns a copy of ‘sequence’ with all elements ‘equal’ to ‘object’ removed.
This function is the non-destructive counterpart of ‘delete’. It returns a copy of ‘sequence’, a list, vector, or string, with elements ‘equal’ to ‘object’ removed.
This function is like ‘member’, except that OBJECT should be a string and that it ignores differences in letter-case and text representation: upper-case and lower-case letters are treated as equal, and unibyte strings are converted to multibyte prior to comparison.
This function destructively removes all ‘equal’ duplicates from LIST, stores the result in LIST and returns it. Of several ‘equal’ occurrences of an element in LIST, ‘delete-dups’ keeps the first one.
Previous: Modifying List Variables, Up: Sequence Functions [Index]