summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNic Ferier <nic@ferrier.me.uk>2012-12-28 19:29:33 +0000
committerNic Ferier <nic@ferrier.me.uk>2012-12-28 19:29:33 +0000
commitf94e77e790db1b3bc356c86f5ee7ae10d3e1ccba (patch)
tree6bb553757d4d432e14d24cba7c8739bd6571fa98
parent446800fd8e1339b3245d1c9b6e3cd070c24b29c9 (diff)
add kvalist-set-value! - destructive setting key/values in alist
-rw-r--r--kv.el18
1 files changed, 18 insertions, 0 deletions
diff --git a/kv.el b/kv.el
index 58532b8..ab7db44 100644
--- a/kv.el
+++ b/kv.el
@@ -297,6 +297,24 @@ Use this as the function to pass to `sort'."
"Do a sort using `kvcmp'."
(sort lst 'kvcmp))
+(progn
+ (put 'kvalist-key
+ 'error-conditions
+ '(error))
+ (put 'kvalist-key
+ 'error-message
+ "No such key found in alist."))
+
+(defun kvalist-set-value! (alist key value)
+ "Destructively set the value of KEY to VALUE in ALIST.
+
+If the assoc is not found this adds it to alist."
+ (let ((cell (assoc key alist)))
+ (if (consp cell)
+ (setcdr cell value)
+ ;; Else what to do?
+ (signal 'kvalist-key (list alist key)))))
+
(defun kvdotassoc-fn (expr table func)
"Use the dotted EXPR to access deeply nested data in TABLE.