Summary: An ordered hash that does not support deletes could cause a
user visible bug.  At a minimum it should support the special case of
delete that is supported by the Perl each() operator.

Details: This Week in Perl 6, May 25, 2005-May 31, 2005
http://www.perl.com/pub/a/2005/06/p6pdigest/20050602.html  has a brief
discussion of Ordered Hashes with this link
http://groups-beta.google.com/group/perl.perl6.internals/browse_frm/thre
ad/86466b906c8e6e10/24a935c5c2c71aa8#24a935c5c2c71aa8 where Dan Sugalski
says: "I'd just pitch an exception if code deletes an entry  ..."
Perhaps this is OK, because this code is intended for internal use only.
But people like to reuse code, and if anyone writes an ordered hash
module on top of this code it will have a bug.  There are already two
ordered hash modules, and at one time they both had a bug involving
delete.  On March 10, 2004 I sent email about this to the authors of
Tie::LLHash (Ken Williams) and Tie::IxHash (Gurusamy Sarathy) and also
to [EMAIL PROTECTED]  (Ken then fixed the bug in
Tie::LLHash.)  Because that email does not seem to be archived anywhere.
I am including the most relevant part here:
There is a bug in Tie::IxHash and also Tie::LLHash.
The bug is caused by using a delete in a loop .

# This *IS* a bug because
# http://www.perldoc.com/perl5.8.0/pod/func/each.html says:
# It is always safe to delete the item most recently returned by
# each(), which means that the following code will work:
#        while (($key, $value) = each %hash) {
#          print $key, "\n";
#          delete $hash{$key};   # This is safe
#        }

P.S. I am sending this as email to perl6-internals.  Should I instead
post to the news group?  That is harder for me, but doable if it is the
right thing.
.
Hopefully helpfully yours,
Steve
-- 
Steve Tolkin    Steve . Tolkin at FMR dot COM   617-563-0516 
Fidelity Investments   82 Devonshire St. V4D     Boston MA 02109
There is nothing so practical as a good theory.  Comments are by me, 
not Fidelity Investments, its subsidiaries or affiliates.







Reply via email to