Create Lists, plists, alists

  • Create a list:
(list 1 2 3)
  • You can put any compound elements in a list:
(list :one "two" (list 3))
  • You can also use make-list. It requires a size argument, initial-element is set to nil by default, and it gives the same initial element to all parts of the list.
(make-list size &key initial-element)
(make-list 3 :initial-element "hello")
  • The fill function will put whatever we give it in the list.
(fill sequence item &key (start 0) end)
(fill * 1)
  • Beware that (list 1 2 3) is not the same as quote '(1 2 3)
  • '(...) shorthand for (quote ...) will not evaluate the arguments that we pass to it.

Property Lists (plist)

A plist is simply a list where you alternate a key and a value. The key of a plist cannot be a string, but can be a keyword or a symbol. In this example it is a keyword.

(defparameter *plist* (list :key "foo" :key2 "bar"))
  • Access an element
(getf *plist* :key)
  • Remove an element (destructive). Returns T if such a Property was present, NIL if not.
(remf *plist* :key2)

Association Lists (aList)

(defparameter *my-alist* (list (cons :foo "foo")
                               (cons :bar "bar")))

'((:foo . "foo") (:bar . "bar"))

(list (cons :name *name*)
      (cons :name "me"))
  • Access:
(assoc :foo *my-alist*)