Re: Bug in (remhash) ??
JP Massar <[email protected]> Sat, 03 May 2003 10:41:29 -0700
| Newsgroups | gmane.lisp.corman |
|---|---|
| Message-ID | <[email protected]> |
At 09:19 AM 5/3/03 +0000, lcluke wrote:
>Am I going nuts, or is this a bug in (remhash) ? It doesn't seem to
>remove the entry from the hash table.
>
>(setf a-hash (make-hash-table))
>
>#<HASHTABLE 0/211>
>
>(setf (gethash 'A_TEST a-hash) 'HASH_TABLE_ENTRY)
>
>HASH_TABLE_ENTRY
>
>(gethash 'A_TEST a-hash)
>
>HASH_TABLE_ENTRY
>T
>
>(remhash 'A_TEST a-hash)
>T
>
>(gethash 'A_TEST a-hash)
>HASH_TABLE_ENTRY
>T
It's a bug.
Here's a patch I came up with.
--------------------------------
(in-package :lisp)
;;; Problem:
;;; (setq (make-hash-table))
;;; (setf (gethash 'fred x) 5)
;;; (remhash 'fred x)
;;; (gethash 'fred x) --> 5
;;; Solution: DELETE-KEY-VALUE was not testing against the real key
;;; all the time
(defun delete-key-value (list key test)
(if (null list)
list
;; used to be (funcall test key (car list))
(if (funcall test key (if (consp (car list)) (caar list) (car list)))
(cddr list)
(do* ((x list (cddr x))
(y (cddr list) (cddr y))
(hkey (car y) (car y)))
((null y) list)
(if (consp hkey)
(setf hkey (car hkey)))
(if (funcall test key hkey)
(rplacd (cdr x) (cddr y)))))))
------------------------ Yahoo! Groups Sponsor ---------------------~-->
Rent DVDs from home.
Over 14,500 titles. Free Shipping
& No Late Fees. Try Netflix for FREE!
http://us.click.yahoo.com/BVVfoB/hP.FAA/uetFAA/SyjtlB/TM
---------------------------------------------------------------------~->
To unsubscribe from this group, send an email to:
[email protected]
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/