Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
(defgeneric put-method-for (mode)
(:method ((mode (eql :replace))) #'kcdbset)
(:method ((mode (eql :keep))) #'kcdbadd)
(:method ((mode (eql :concat))) #'kcdbappend))
(defun put (key value &key (mode :replace))
(funcall (put-method-for mode) key value))
;; definitions of methods for kcdbset, kcdbadd, and kcdbappend define methods
;; that store key/value pairs with different behaviors based on whether
;; that key already exists.
;; For more info see:
;; Usage...
;; Will store some_val under some_key
(put "some_key" "some_val" :mode :replace)
;; Will not do anything, as it will invoke kcdbadd, which does
;; nothing if the key exists
(put "some_key" "some_val" :mode :keep)
;; Will add some_val2 to some_key by using kcdbappend
(put "some_key" "some_val2" :mode :concat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment