Add setf method for alexandria:ensure-gethash
I often want to do things like have hash tables that are list-valued (i.e., default to nil
) and that can be set with push
without having to worry about whether they have already been set (as an aside, Python's defaultdict
provides this same facility in a different way).
So I added the following setf
method for ensure-gethash
:
(#+sbcl sb-ext:without-package-locks
#-sbcl progn
(defsetf alexandria:ensure-gethash (key table &optional default) (value)
(let ((tempvar (gensym "TMP")))
`(let ((,tempvar (alexandria:ensure-gethash ,key ,table ,default)))
(declare (ignorable ,tempvar))
(setf (gethash ,key ,table) ,value)))))