PEP 218 Re: ANN: set-0.1 module available

Steve Holden sholden at holdenweb.com
Sun May 19 15:37:47 EDT 2002


"Fernando Pérez" <fperez528 at yahoo.com> wrote ...
> James J. Besemer wrote:
>
> > Actually Denis seemed to be suggesting that sets themselves should be
> > immutable so they could Serve as dictionary keys.  I think it's very
> > plausable that sets would be used in this manner..
>
> I beg to differ. Mathematically, there's nothing in the idea of a set that
> makes it immutable. I know that Python is not a mathematics-only language,
> but much of the cleanliness of its design does come from following
abstract
> ideas as much as is reasonable. And enforcing immutability on a set is one
> hell of a breakage for an object as basic to many mathematical ideas as a
set
> is.
>
Well, mathematically there's nothing in the idea of a tuple that implies
mutability, but we have lists and tuple because it is convenient to have two
similar sequence types, one of which is mutable and the other of which is
not. So it probably isn't useful to argue from mathematics when what you are
taking about is the pragmatics of programming.

> I guess if you want to insist on sets being usable as keys you might come
up
> with a pair of set-like types just like we have lists/tuples. But if sets
are
> ever going to be part of the language, _please_ don't make them immutable.
In
> my mind, that's like saying that you add integers to a language but you
can't
> do arithmetic with them ;)
>

Bearing in mind that Python does indeed allow you to do arithmetic with
integers which are immutable, I'm wondering if you might not need to look
for a rather better analogy.

I believe (without any worked-out justification) that Python could actually
perform exactly the same comutations as it does now even if lists were
removed: it would simply be more awkward and less efficient to compute with
tuples, which are immutable.

If sets were to become a Python type I would expect that it would be useful
to have both mutable and immutable variants, in just the same way as the
sequences do. The strings are a degenerate example (IMHO), because they are
the only sequence type in Python where type(s[n]) == type(s) for any valid n
(I know I've not expressed that well: what I'm trying to say is that it's a
little bizarre for strings to be sequences of strings of length one. It
works, but it's a little bizarre).

regards
 Steve
--
-----------------------------------------------------------------------
Steve Holden                                 http://www.holdenweb.com/
Python Web Programming                http://pydish.holdenweb.com/pwp/
-----------------------------------------------------------------------








More information about the Python-list mailing list