Is it ok to remove hash table entries during maphash? For instance, is
it guaranteed that the following functions will work as expected:
(defun delete-odds (ht)
(maphash (lambda (k v)
(when (oddp k) (remhash k ht))) ht)
ht)
?
On Tue, 07 Jun 2005 23:08:35 +0400, V.Ch. wrote:
> Is it ok to remove hash table entries during maphash? For instance, is
> it guaranteed that the following functions will work as expected:
>
> (defun delete-odds (ht)
> (maphash (lambda (k v)
> (when (oddp k) (remhash k ht))) ht)
> ht)
>
> ?
http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
--
mvh,
Lars Rune Nøstdal
http://lars.nostdal.org/
On Tue, 07 Jun 2005 23:05:24 +0200, Lars Rune Nøstdal wrote:
> On Tue, 07 Jun 2005 23:08:35 +0400, V.Ch. wrote:
>
>> Is it ok to remove hash table entries during maphash? For instance, is
>> it guaranteed that the following functions will work as expected:
>>
>> (defun delete-odds (ht)
>> (maphash (lambda (k v)
>> (when (oddp k) (remhash k ht))) ht)
>> ht)
>>
>> ?
>
> http://www.lispworks.com/documentation/HyperSpec/Body/03_f.htm
Oh, and this also talks about this:
http://www.lispworks.com/documentation/HyperSpec/Body/f_maphas.htm
"The consequences are unspecified if any attempt is made to add or remove
an entry from the hash-table while a maphash is in progress, with two
exceptions: the function can use can use setf of gethash to change the
value part of the entry currently being processed, or it can use remhash
to remove that entry."
--
mvh,
Lars Rune Nøstdal
http://lars.nostdal.org/