Freezing a mutable (was Re: lambda)

Antoon Pardon apardon at forel.vub.ac.be
Thu Jan 20 07:19:11 EST 2005


Op 2005-01-20, Nick Coghlan schreef <ncoghlan at iinet.net.au>:
> Antoon Pardon wrote:
>> Interesting idea. But I think you are wrong when you say that two lists
>> that compare equal at the time they are frozen, will get the same
>> dictionary entry. The problem is an object must compare equal to
>> the key in the dictionary to get at the same entry. So if you freeze
>> a list and its copy but then mutate them differently, they no longer
>> are equal and so wont get you at the same entry.
>
> The trick is that the result of the freezing operation is cached until such time 
> as you explicitly unfreeze the object.

I missed that you would use it with the idiom: dct[x.frozen()]

I have two problems with this approach.

1) It doesn't work when you get your keys via the keys/items
   methods.

2) This is rather minor, but a user could still unfreeze
   untimely 

-- 
Antoon Pardon



More information about the Python-list mailing list