Skip to content
Browse files

new function to convert alist keys into symbols

  • Loading branch information...
1 parent 8a19f5d commit 13311d9d667a79e0c174054487e099e2f67ec1b4 @nicferrier committed Sep 16, 2012
Showing with 17 additions and 0 deletions.
  1. +8 −0 kv-tests.el
  2. +9 −0 kv.el
View
8 kv-tests.el
@@ -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
View
9 kv.el
@@ -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.

0 comments on commit 13311d9

Please sign in to comment.
Something went wrong with that request. Please try again.