diff options
author | Nic Ferier <nic@ferrier.me.uk> | 2012-12-28 19:29:33 +0000 |
---|---|---|
committer | Nic Ferier <nic@ferrier.me.uk> | 2012-12-28 19:29:33 +0000 |
commit | f94e77e790db1b3bc356c86f5ee7ae10d3e1ccba (patch) | |
tree | 6bb553757d4d432e14d24cba7c8739bd6571fa98 | |
parent | 446800fd8e1339b3245d1c9b6e3cd070c24b29c9 (diff) |
add kvalist-set-value! - destructive setting key/values in alist
-rw-r--r-- | kv.el | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -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. |