[alexandria-devel] [PATCH] lazy-evaluate the default value in ENSURE-GETHASH
Ryan Davis
ryan at acceleration.net
Wed Dec 21 18:30:59 UTC 2011
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,
--
Ryan Davis
Acceleration.net
Director of Programming Services
2831 NW 41st street, suite B
Gainesville, FL 32606
Office: 352-335-6500 x 124
Fax: 352-335-6506
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-lazy-evaluate-the-default-value-in-ENSURE-GETHASH.patch
URL: <https://mailman.common-lisp.net/pipermail/alexandria-devel/attachments/20111221/c1de7452/attachment.ksh>
More information about the alexandria-devel
mailing list