Re: [alexandria-devel] [PATCH] lazy-evaluate the default value in ENSURE-GETHASH

2011-12-30 Thread Nikodemus Siivola
On 21 December 2011 20:30, Ryan Davis r...@acceleration.net wrote:
 I'm using a hash-table as a cache, and had a problem with
 ensure-gethash. Some example code / output:

I must be missing something. Why the CONSTANTP and LAMBDA instead of

(defmacro ensure-gethash (key hash-table optional default)
  Like GETHASH, but if KEY is not found in the HASH-TABLE saves the DEFAULT
under key before returning it. Secondary return value is true if key was
already in the table.
  `(multiple-value-bind (value ok) (gethash ,key ,hash-table)
 (if ok
 (values value ok)
 (values (setf (gethash ,key ,hash-table) ,default) nil

?

Cheers,

 -- nikodemus

___
alexandria-devel mailing list
alexandria-devel@common-lisp.net
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/alexandria-devel


Re: [alexandria-devel] [PATCH] lazy-evaluate the default value in ENSURE-GETHASH

2011-12-22 Thread Hans Hübner
On Wed, Dec 21, 2011 at 7:30 PM, Ryan Davis r...@acceleration.net wrote:
 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).
[...]
 Thoughts?

I'd like to see this in alexandria, as it is a very common idiom for me.

-Hans

___
alexandria-devel mailing list
alexandria-devel@common-lisp.net
http://lists.common-lisp.net/cgi-bin/mailman/listinfo/alexandria-devel