Monday, July 27, 2009

Summary of the List Data Structure

Here, I give a list of the major functions that deal with manipulating the list data structure in emacs lisp. Most of the functions given below were found in the emacs reference manual in chapter 5. Some of them have been explained in the previous posts.

Functions' List

  1. consp, atom, listp, nlistp, null
  2. car, cdr, car-safe, cdr-safe, caar, cddr ...
  3. pop, nthcdr, nth, last, butlast, nbutlast
  4. cons, list, make-list, append, copy-tree, number-seqeunce,
  5. add-to-list, add-to-ordered-list,
  6. setcar, setcdr,
  7. nconc, nreverse, reverse, sort
  8. eq, eq1, equal
  9. memq, delq, remq, memq1, member, delete, remove, member-ignore-case, delete-dups
  10. assoc, rassoc, assq, rassq, assoc-default, copy-alist, assq-delete-all, rassq-delete-all


Some notes regarding the above functions.
  • The function (nth n list) returns the n-1th element (zero-based indexing) of list and is equivalent to (car (nthcdr n list))
  • (last list &optional n) returns the last element of the list if n is zero or not specified else it returns the last n elements
  • (butlast list &optional n) returns all elements of the list excluding the last element of the list if n is zero or nil else it returns the first n elements of list.
  • Many functions that start with the letter 'n' such as nconc, nreverse are destructive counterparts to the non-destructive functions such as append, reverse.


Post a Comment