Forming Subsets and Deleting Cases

The "2D select function allows you to select a single element or a group of elements from a list or vector. For example, if we define "2D x by
(def x (list 3 7 5 9 12 3 14 2))
then "2D (select x i) will return the i-th element of "2D x. LISP, like the language C but in contrast to Fortran, numbers elements of list and vectors starting at zero. Thus the indices for the elements of "2D x are 0, 1, 2, 3, 4, 5, 6, 7 . So
> (select x 0)
3
> (select x 2)
5
To get a group of elements at once we can use a list of indices instead of a single index:
> (select x (list 0 2))
(3 5)

If you want to select all elements of x except element 2 you can use the expression

(remove 2 (iseq 0 7))
as the second argument to the function select:
> (remove 2 (iseq 0 7))
(0 1 3 4 5 6 7)
> (select x (remove 2 (iseq 0 7)))
(3 7 9 12 3 14 2)
Another approach is to use the logical function "2D /= (meaning not equal) to tell you which indices are not equal to 2. The function "2D which can then be used to return a list of all the indices for which the elements of its argument are not NIL:
> (/= 2 (iseq 0 7))
(T T NIL T T T T T)
> (which (/= 2 (iseq 0 7)))
(0 1 3 4 5 6 7)
> (select x (which (/= 2 (iseq 0 7))))
(3 7 9 12 3 14 2)
This approach is a little more cumbersome for deleting a single element, but it is more general. The expression "2D (select x (which (< 3 x))), for example, returns all elements in "2D x that are greater than 3:
> (select x (which (< 3 x)))
(7 5 9 12 14)