title: How can I reuse a gethash lookup in Common Lisp?
body: <p>I have a hash table where the keys are rather complex lists, with sublists of symbols and integers, and the value should be modified depending on the already existing value. The table is created with <code>:test #'equal</code>.</p>
  
  <p>I do something similar to this a lot:</p>
  
  <pre><code>(defun try-add (i)
    (let ((old-i (gethash complex-list table nil)))
      (if (may-add old-i)
        (push i (gethash complex-list table)))))
  </code></pre>
  
  <p>Profiling shows that <code>equal</code> tests take a lot of time. I have an optimization idea, that the amount of <code>gethash</code> lookups could be reduced from two to one. It can be done in C++ by reusing the iterator, but not sure how this would be done in Lisp. Any ideas?</p>