[Python-3000] sets in P3K?
Jim Jewett
jimjjewett at gmail.com
Fri Apr 28 18:45:23 CEST 2006
On 4/28/06, Greg Wilson <gvwilson at cs.utoronto.ca> wrote:
> - introduce '@' as a prefix operator meaning 'freeze'.
I mostly like the concept, but not the operator. Using @ limits it to
syntax-created literals (because of ambiguity with decorators). Since
numbers are already immutable, that basically means lists, dicts, and
maybe sets, but not even user-defined subclasses. (And you don't have
to do it with tuples, because ... uh ...) I'm not sure what to use
instead, except maybe for the backwards quote, which means I have to
duck now too. ("frozen" or "snapshot" might be too long to be
useful.)
I am slightly concerned that it *might* be a bad idea to encourage
immutable containers, in the same way that it can be a bad idea to
prevent subclassing or even to use a __slots__ field.
> - [1, 2, 3] is a mutable sequence (our old friend the list)
>
> - {1, 2, 3} is a mutable set
>
> - @{1, 2, 3} is an immutable set (i.e., a frozen set --- frozen
> at creation, so all current optimizations possible)
>
> - @[1, 2, 3] is an immutable sequence (i.e., a tuple)
Are there still plans to push the claim that lists hold a homogenous
collection, and tuples don't? A frozen list (and a mutable tuple)
would make that claim easier to defend, but it still wouldn't be easy.
I'm inclined to go with real objects and named attributes...
> Now, if only I can figure out whether "@x" means "bind the name x
> permanently to its current value to create a symbolic constant" or "freeze
> the object to which x currently refers"... ;-)
If it is really limited to literals, then I'm not sure it matters; the
freeze should have the only reference. Unless you were thinking of
supporting horrible things like
x=@[1,2,3]
y=x
y.append(4) # a different *name*, so we can now treat it mutably
-jJ
More information about the Python-3000
mailing list