(defun aget (a-list key)
(cdr (assoc key a-list)))
(define-setf-expander aget (a-list-form key-form &environment env)
(multiple-value-bind (vars vals store setter getter) (get-setf-expansion a-list-form env)
(let ((key-var (gensym "KEY-"))
(entry (gensym "ENTRY-"))
(alist (gensym "ALIST-")))
(values (cons key-var vars)
(cons key-form vals)
store
`(let* ((,alist ,getter)
(,entry (assoc ,key-var ,alist)))
(if ,entry
(rplacd ,entry ,(first store))
(setf ,alist (acons ,key-var ,(first store) ,alist)))
(let ((,(first store) ,alist))
,setter)
,(first store))
`(cdr (assoc ,key-var ,getter))))))
(let ((alists (vector '() () ()))
(i -1))
(setf (aget (aref alists (incf i)) :k1) 11
(aget (aref alists (incf i)) :k1) 12
(aget (aref alists (incf i)) :k1) 13
i -1
(aget (aref alists (incf i)) :k2) 21
(aget (aref alists (incf i)) :k2) 22
(aget (aref alists (incf i)) :k2) 23
i -1
(aget (aref alists (incf i)) :k1) 100
(aget (aref alists (incf i)) :k2) 200
(aget (aref alists (incf i)) :k3) 300)
(print alists))
KGRlZnVuIGFnZXQgKGEtbGlzdCBrZXkpCiAgKGNkciAoYXNzb2Mga2V5IGEtbGlzdCkpKQoKKGRlZmluZS1zZXRmLWV4cGFuZGVyIGFnZXQgKGEtbGlzdC1mb3JtIGtleS1mb3JtICZlbnZpcm9ubWVudCBlbnYpCiAgKG11bHRpcGxlLXZhbHVlLWJpbmQgKHZhcnMgdmFscyBzdG9yZSBzZXR0ZXIgZ2V0dGVyKSAoZ2V0LXNldGYtZXhwYW5zaW9uIGEtbGlzdC1mb3JtIGVudikKICAgIChsZXQgKChrZXktdmFyICAgKGdlbnN5bSAiS0VZLSIpKQogICAgICAgICAgKGVudHJ5ICAgICAoZ2Vuc3ltICJFTlRSWS0iKSkKICAgICAgICAgIChhbGlzdCAgICAgKGdlbnN5bSAiQUxJU1QtIikpKQogICAgICAodmFsdWVzIChjb25zIGtleS12YXIgIHZhcnMpCiAgICAgICAgICAgICAgKGNvbnMga2V5LWZvcm0gdmFscykKICAgICAgICAgICAgICBzdG9yZQogICAgICAgICAgICAgIGAobGV0KiAoKCxhbGlzdCAsZ2V0dGVyKQogICAgICAgICAgICAgICAgICAgICAgKCxlbnRyeSAoYXNzb2MgLGtleS12YXIgLGFsaXN0KSkpCiAgICAgICAgICAgICAgICAgKGlmICxlbnRyeQogICAgICAgICAgICAgICAgICAgICAocnBsYWNkICxlbnRyeSAsKGZpcnN0IHN0b3JlKSkKICAgICAgICAgICAgICAgICAgICAgKHNldGYgLGFsaXN0IChhY29ucyAsa2V5LXZhciAsKGZpcnN0IHN0b3JlKSAsYWxpc3QpKSkKICAgICAgICAgICAgICAgICAobGV0ICgoLChmaXJzdCBzdG9yZSkgLGFsaXN0KSkKICAgICAgICAgICAgICAgICAgICxzZXR0ZXIpCiAgICAgICAgICAgICAgICAgLChmaXJzdCBzdG9yZSkpCiAgICAgICAgICAgICAgYChjZHIgKGFzc29jICxrZXktdmFyICxnZXR0ZXIpKSkpKSkKCihsZXQgKChhbGlzdHMgKHZlY3RvciAnKCkgKCkgKCkpKQogICAgICAoaSAtMSkpCiAgKHNldGYgKGFnZXQgKGFyZWYgYWxpc3RzIChpbmNmIGkpKSA6azEpIDExCiAgICAgICAgKGFnZXQgKGFyZWYgYWxpc3RzIChpbmNmIGkpKSA6azEpIDEyCiAgICAgICAgKGFnZXQgKGFyZWYgYWxpc3RzIChpbmNmIGkpKSA6azEpIDEzCiAgICAgICAgaSAtMQogICAgICAgIChhZ2V0IChhcmVmIGFsaXN0cyAoaW5jZiBpKSkgOmsyKSAyMQogICAgICAgIChhZ2V0IChhcmVmIGFsaXN0cyAoaW5jZiBpKSkgOmsyKSAyMgogICAgICAgIChhZ2V0IChhcmVmIGFsaXN0cyAoaW5jZiBpKSkgOmsyKSAyMwogICAgICAgIGkgLTEKICAgICAgICAoYWdldCAoYXJlZiBhbGlzdHMgKGluY2YgaSkpIDprMSkgMTAwCiAgICAgICAgKGFnZXQgKGFyZWYgYWxpc3RzIChpbmNmIGkpKSA6azIpIDIwMAogICAgICAgIChhZ2V0IChhcmVmIGFsaXN0cyAoaW5jZiBpKSkgOmszKSAzMDApCiAgKHByaW50IGFsaXN0cykpCgo=