Last active
November 25, 2020 21:32
-
-
Save defunkydrummer/9233877a851a4ba97057f31f9edea836 to your computer and use it in GitHub Desktop.
Helper for traversing ALISTs in depth
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun geta (alist key) | |
"Similar to assoc-value... but operates in depth! | |
key can be a list or a single key." | |
(when (and alist key) | |
(etypecase key | |
((or string symbol) | |
(alexandria:assoc-value alist key :test 'string=)) | |
(cons | |
;; associate in depth | |
(if (cdr key) | |
(geta (alexandria:assoc-value alist (car key) :test 'string=) | |
(cdr key)) | |
;; else: only one key in list. | |
(alexandria:assoc-value alist (car key) :test 'string=)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This assumes the alexandria library is loaded.
Of course, assoc-value is the same as (cdr (assoc key alist :test ...))
Of course this can be improved so you pass the test function to use, and remove the dependency on alexandria. I am posting this as a quick and dirty way to traverse the alists.