Skip to content

Commit

Permalink
new function to convert alist keys into symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
nicferrier committed Sep 16, 2012
1 parent 8a19f5d commit 13311d9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions kv-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@
'((a . 10)(b . 20)(c . 5))
(sort '((b . 20)(c . 5)(a . 10)) 'kvcmp))))

(ert-deftest kvalist-keys->symbols ()
"Test the key transformation."
(should
(equal
'((a . 10)(\10 . 20)(\(a\ b\ c\) . 30))
(kvalist-keys->symbols
'(("a" . 10)(10 . 20)((a b c) . 30))))))

(ert-deftest kvdotassoc ()
(should
(equal
Expand Down
9 changes: 9 additions & 0 deletions kv.el
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,15 @@ cons cells."
(assoc-default car-key alist)
(assoc-default cdr-key alist)))))

(defun kvalist-keys->symbols (alist)
"Convert the keys in ALIST to symbols."
(mapcar
(lambda (pair)
(cons
(intern (format "%s" (car pair)))
(cdr pair)))
alist))

(defun kvcmp (a b)
"Do a comparison of the two values using printable syntax.
Expand Down

0 comments on commit 13311d9

Please sign in to comment.