Freezing

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Thu Jan 12 13:44:49 EST 2006


Most of my ideas seem usless or stupid, but I think expressing them
here doesn't harm much.
This is an idea for Py 3.0, because it's not backward compatible.

Dicts and sets require immutable keys, like tuples or frozensets, but
to me they look like a duplication. So the idea is to remove tuples and
frozensets (and replace the few other uses of tuples with lists, like
the % interpolation), and to add a freeze operation, to freeze lists,
sets and dicts (etc), so they can be used as keys.

The syntax to do this maybe can be a builtin freeze(data) function, or
a |data|, or something different.
This freezing can be shallow or deep (recursive).

Example:
s = |set(1, 3, 5)|
d1 = |{s:1}|
d2 = {d1:1}

The "|" binary xor can become written "XOR", like the AND, OR, NOT.
The &^~ so become free to be used for other purposes, operator
overloading, etc (silly example: ^ for pow instead of **, so the
**identifier is used only for keyword arguments, etc).

Bye,
bearophile




More information about the Python-list mailing list