Hash table utilities

People have referred to the usage of hashtables in ANSI common lisp as archaic. This isn’t necessarily true, but if you do feel this way there’s no need to stick with it. Here’s an example of how “radical utils” can simplify your life.

> (setf myhash (hash-table-from-alist '((apple . 2) (berry . 5) (lemon . 1))))
#<HASH-TABLE :TEST EQL :COUNT 3 {10060EA0B3}>
> (let ((acc 0))
          (dotable (_ val myhash acc)
        (incf acc val)))
8
> (print-hash-table myhash)
#{
  APPLE 2
  BERRY 5
  LEMON 1
 } 
#<HASH-TABLE :TEST EQL :COUNT 3 {10060EA0B3}>

So, converting from an alist or a plist to a hash table is straightforward, as is iterating over it (notice the use of _ for the ignored “key” value).

(I’m slowly working my way through the (https://github.com/vseloved/rutils), so I hope it’s ok to post little snippets like these as I go along, even though this is a blog and I really should gather them up together. OTOH if I wait that long I’ll never get around to it)