Contents    Page-10    Prev    Next    Page+10    Index   

Association List

An association list or alist is a simple lookup table or map: a linked list containing a key value and some information associated with the key.[The function assoc, traditionally the name of this function in Lisp, is used for a Clojure lookup on the built-in map datatype. The Clojure version would be much more efficient for a large map.]


(assocl 'two '((one 1) (two 2) (three 3)))
    ->  (two 2)


(defn assocl [key lst]
  (if (empty? lst)
      nil
      (if (= (first (first lst)) key)
          (first lst)
          (assocl key (rest lst)) ) ) )