Skip to content

Commit

Permalink
better implementation of kvplist->alist by tali713
Browse files Browse the repository at this point in the history
  • Loading branch information
nicferrier committed Sep 15, 2012
1 parent 929bbec commit 8a19f5d
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions kv.el
Expand Up @@ -71,28 +71,22 @@ HASH-TABLE-ARGS are passed to the hash-table creation."
(car pair))))) (car pair)))))
(cdr pair)))) (cdr pair))))


(defun keyword->symbol (keyword)
"A keyword is a symbol leading with a :.
Converting to a symbol means dropping the :."
(intern (substring (symbol-name keyword) 1)))

(defun kvplist->alist (plist) (defun kvplist->alist (plist)
"Convert PLIST to an alist. "Convert PLIST to an alist.
The keys are expected to be :prefixed and the colons are removed. The keys are expected to be :prefixed and the colons are removed.
The keys in the resulting alist are symbols." The keys in the resulting alist are symbols."
;; RECURSION KLAXON ;; RECURSION KLAXON
(labels (when plist
((plist->alist-cons (a b lst) (destructuring-bind (key value &rest plist) plist
(let ((key (intern (substring (symbol-name a) 1)))) (cons `(,(keyword->symbol key) . ,value)
(if (car-safe lst) (kvplist->alist plist)))))
(cons
(cons key b)
(plist->alist-cons
(car lst)
(cadr lst)
(cddr lst)))
;; Else
(cons (cons key b) nil)))))
(plist->alist-cons
(car plist)
(cadr plist)
(cddr plist))))


(defun kvalist2->plist (alist2) (defun kvalist2->plist (alist2)
"Convert a list of alists too a list of plists." "Convert a list of alists too a list of plists."
Expand Down

0 comments on commit 8a19f5d

Please sign in to comment.