From fefb0a1d032c9d0e90b8aa253920a7541c1393b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salvador=20Fandi=C3=B1o?= <sfand...@yahoo.com> Date: Sat, 25 Apr 2015 17:03:19 +0200 Subject: [PATCH] Fix for ensure-gethash macro
There were at least two bugs there: 1) unintended variable capture 2) multiple evaluation of the key and hash-table arguments --- hash-tables.lisp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/hash-tables.lisp b/hash-tables.lisp index 65253e7..6e0d9ca 100644 --- a/hash-tables.lisp +++ b/hash-tables.lisp @@ -93,7 +93,9 @@ PLIST. Hash table is initialized using the HASH-TABLE-INITARGS." "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)))) + (once-only (key hash-table) + (with-gensyms (value ok) + `(multiple-value-bind (,value ,ok) (gethash ,key ,hash-table) + (if ,ok + (values ,value ,ok) + (values (setf (gethash ,key ,hash-table) ,default) nil)))))) -- 2.1.4