assoc-utils icon indicating copy to clipboard operation
assoc-utils copied to clipboard

Utilities for manipulating association lists.

Assoc-Utils

Build Status Coverage Status Quicklisp dist

Utilities for manipulating association lists.

Usage

aget

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

(aget *person* "name")
;=> "Eitaro"

(aget *person* "address")
;=> NIL

(aget *person* "address" "Tokyo, Japan")
;=> "Tokyo, Japan"

(setf (aget *person* "name") "Eitaro Fukamachi")

*person*
;=> (("name" . "Eitaro Fukamachi") ("email" . "[email protected]"))

remove-from-alist & delete-from-alist

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

(remove-from-alist *person* "name")
;=> (("email" . "[email protected]"))

;; Destructive version
(delete-from-alist *person* "name")
;=> (("email" . "[email protected]"))

alist-plist & plist-alist

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

(alist-plist *person*)
;=> (:NAME "Eitaro" :EMAIL "[email protected]")

(plist-alist '(:name "Eitaro" :email "[email protected]"))
;=> (("name" . "Eitaro") ("email" . "[email protected]"))

alist-hash & hash-alist

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

(alist-hash *person*)
;=> #<HASH-TABLE :TEST EQUAL :COUNT 2 {1004329443}>

(hash-alist *)
;=> (("name" . "Eitaro") ("email" . "[email protected]"))

alist-keys & alist-values

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

(alist-keys *person*)
;=> ("name" "email")

(alist-values *person*)
;=> ("Eitaro" "[email protected]")

alistp

(alistp '(("name" . "Eitaro") ("email" . "[email protected]")))
;=> T

(alistp 1)
;=> NIL

(alistp nil)
;=> T

;; Type: alist is also available
(typep '(("name" . "Eitaro") ("email" . "[email protected]")) 'alist)
;=> T

alist=

(alist= '(("name" . "Eitaro") ("email" . "[email protected]"))
        '(("email" . "[email protected]") ("name" . "Eitaro")))
;=> T

Installation

(ql:quickload :assoc-utils)

Author

License

Assoc-Utils is free and unencumbered software released into the public domain.