Skip to content

Latest commit

 

History

History
74 lines (55 loc) · 1.83 KB

0083-assoc-utils.org

File metadata and controls

74 lines (55 loc) · 1.83 KB

assoc-utils

This is a small utility library by Eitaro Fukamachi. It serves a single purpose - make working with alists more convenient.

The library has good documentation with lots of examples. Here is the excerpt from it:

POFTHEDAY> (defvar *person*
             '(("name" . "Eitaro")
               ("email" . "[email protected]")))

POFTHEDAY> (assoc-utils:aget *person* "name")
"Eitaro"

POFTHEDAY> (assoc-utils:aget *person* "address")
NIL

POFTHEDAY> (assoc-utils:aget *person* "address"
                             ;; This is default
                             "Tokyo, Japan")
"Tokyo, Japan"

;; The alist remains the same
POFTHEDAY> *person*
(("name" . "Eitaro") ("email" . "[email protected]"))

;; But aget is setf-able:
POFTHEDAY> (setf (assoc-utils:aget *person* "address")
                 "Tokyo, Japan")

POFTHEDAY> *person*
(("address" . "Tokyo, Japan")
 ("name" . "Eitaro")
 ("email" . "[email protected]"))

POFTHEDAY> (assoc-utils:delete-from-alistf *person*
                                           "email")
(("address" . "Tokyo, Japan")
 ("name" . "Eitaro"))

There are also conversion functions which automatically converts keys from strings to keywords and vice versa:

POFTHEDAY> *person*
(("address" . "Tokyo, Japan") 
 ("name" . "Eitaro"))

POFTHEDAY> (assoc-utils:alist-plist *person*)
(:ADDRESS "Tokyo, Japan"
 :NAME "Eitaro")

POFTHEDAY> (assoc-utils:plist-alist *)
(("address" . "Tokyo, Japan")
 ("name" . "Eitaro"))

Read the documentation to learn more about other functions which allow to compare alists, check their type and to get keys and values.