Tuple Format?

Rainer Deyke root at rainerdeyke.com
Mon Sep 4 20:10:26 CEST 2000


"Gene C" <gchiaramonte at yahoo.com> wrote in message
news:J3Os5.19292$K4.855344 at newsread1.prod.itd.earthlink.net...
> I do like the concept of adding a modifier to a list to show it is not
> modifiable, ie a tuple. What about adding the backquote to the beginning
of
> the list?
>
> `[] == ()
> '[1] == (1,)
> `[1, 2, 3] = (1, 2, 3)
>
> Now we have some consistency.
>
> Since a one character string is not written as "a," and a one element list
> does not have to be written as [1,] although it can be, I do not believe
> this discussion to be moot. If you want to see the evil of keeping
oddities
> check out c++ or perl. :-)

Why use tuples at all?  The Pythonic way to enforce usage restrictions is
through convention:

a = [1, 2, 3] # Do not modify this object!

Another, more general way of dealing with mutable/immutable objects would be
to introduce the concept of const references:

a = [1, 2, 3]
print isconst(a) # Prints 0
b = const(a)
print isconst(a) # Prints 0
print isconst(b) # Prints 1

Unfortunately this would either add to the memory footprint of each
reference or require an additional level of indirection for const objects.
Of course, const could also be implemented at the object level, adding to
the memory footprint of objects instead of references.

a = [1, 2, 3]
print isconst(a) # Prints 0
b = const(a)
print isconst(a) # Prints 1
print isconst(b) # Prints 1


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list