8
88888 Dihedral
Rick Johnsonæ–¼ 2013å¹´2月13日星期三UTC+8上åˆ1時48分07秒寫é“:
Yes, a tuple of constant objects is still not clear.
I nominate this line as "bemusing head-scratcher of the week".
Actually the statement is fact IF you can grok it through the eyes of clarity.
"A permanently mutated list..."
A list that has been mutated permanently, that is, it cannot be changed back into a list. psst: i have a sneaking suspicion that he his referring totuples, let's see.
"...is a tuple..."
Ha! Well in Python the immutable sequence type /is/ a tuple after all.
"...of constant objects..."
The tuple contains objects, and it's objects will maintain a constant ordering (relatively in tuple structure) until until the tuple's death.
a1=[1,2,3]
tuple1=(a1,4,5,6)
tuple1 ([1, 2, 3], 4, 5, 6)
a1=[1,2]
tuple1 ([1, 2, 3], 4, 5, 6)
Yes, a tuple of constant objects is still not clear.
Your confusion may stem from interpreting "constant" as the CS term "CONSTANT"[1]; whereby the objects in the tuple are programming CONSTANTS, that is, unable to change. But in reality, although a tuple (bka:StaticList) cannot expand to add more objects, or shrink to eject existing objects, the objects themselves CAN change their own internal state WITHOUT disrupting theimmutable harmony of the tuple.
Observe:
py> class Foo(object):
pass
py> foo = Foo()
py> t = (1,'1', foo)
py> t
(1, '1', <__main__.Foo object at 0x0267BF50>)
py> t[-1].bar = "abc"
py> t
(1, '1', <__main__.Foo object at 0x0267BF50>)
Or by expanding a list
py> t = (1,2,3)
py> t = t+([],)
py> t
(1, 2, 3, [])
py> t[-1].append('circus')
py> t
(1, 2, 3, ['circus'])
[1] Which is an unfortunate side-effect of polysemy and compounded exponentially by naive (and sometimes a purely malevolent intent when) transformation of words into esoteric problem domains.