I'm using a hash-table as a cache, and had a problem with ensure-gethash. Some example code / output:
CL-USER> (let ((h (make-hash-table))) (alexandria:ensure-gethash :x h (progn (format T "expensive computation~%") 1)) (alexandria:ensure-gethash :x h (progn (format T "expensive computation~%") 1))) expensive computation expensive computation 1 T CL-USER>
This patch (created using git format-patch origin/master) converts ENSURE-GETHASH to a macro that only evaluates the default if we get to the setf branch. Has a check to create and call a lambda if the default value looks complicated (using CONSTANTP).
After applying my patch, here's the output: CL-USER> (let ((h (make-hash-table))) (alexandria:ensure-gethash :x h (progn (format T "expensive computation~%") 1)) (alexandria:ensure-gethash :x h (progn (format T "expensive computation~%") 1))) expensive computation 1 T CL-USER>
Thoughts?
Thanks,