RSS Feed

Lisp Project of the Day

assoc-utils

You can support this project by donating at:

Donate using PatreonDonate using Liberapay

assoc-utilsdata-structuresutils

Documentation😀
Docstrings🥺
Tests 😀
Examples😀
RepositoryActivity🥺
CI 😀

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" . "e.arrows@gmail.com")))

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" . "e.arrows@gmail.com"))

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

POFTHEDAY> *person*
(("address" . "Tokyo, Japan")
 ("name" . "Eitaro")
 ("email" . "e.arrows@gmail.com"))

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.


Brought to you by 40Ants under Creative Commons License