Python not a Very High-Level Language?

Michael Hudson mwh21 at cam.ac.uk
Wed Jan 12 14:21:49 EST 2000


neelk at brick.cswv.com (Neel Krishnaswami) writes:

> Tres Seaver <tseaver at aftershock.neosoft.com> wrote:
> > 
> > What reasonable use can you propose for an associative container
> > which allows mutable keys?  You might as well revert to a list of
> > (key,value) pairs, since you're going to do a linear search on each
> > lookup anyway if the keys are allowed to change.
> 
> You can compute the hash function using the object's identity, rather
> than its value. IOW, hash on the object's address. Then you can mutate
> the contents of the object as needed and still access the hash. In
> fact, I believe this is the default behavior for Common Lisp hash
> tables (though of course you can create hash tables with different
> hash functions).

But then you have problems along these lines:

>>> d={}
>>> d[id("!2")] = 1
>>> d[id("!2")]
Traceback (innermost last):
  File "<stdin>", line 1, in ?
KeyError: 135419160

(I had to be a bit sneaky to make sure the string didn't get interned,
which possibly just hilights the problem more...)

Object equality is something that there is no right answer to; I don't
think Common Lisp has all of eq, eql, equal and equalp for the sheer
fun of it.

Using object identity would make using lists as keys (which is where
this started) almost impossible, too.

Cheers,
Michael



More information about the Python-list mailing list