Re: space effecient representations of list subsets (addendum)

Tim Peters (tim@ksr.com)
Fri, 03 Dec 93 14:12:03 EST

> Of course, implicit in the previous long discussion, was the question:
> "Is any of that necessary?"

I don't think so, Steve. Consider the output of this little program:

list = ['abc', ('ABC', 'QRS'), {'a':'b'}, ['A',('B',),'C'] ]

sublist = [ list[0], list[1], list[2], list[3] ]
sl2 = sublist[:]

def print_list_ids( tag, list ):
print 'top ids for', tag + ':\t',
for x in list:
print id(x),
print

print_list_ids('list',list)
print_list_ids('sublist',sublist)
print_list_ids('sl2',sl2)

On this machine it produces

top ids for list: 310528 380472 380504 380912
top ids for sublist: 310528 380472 380504 380912
top ids for sl2: 310528 380472 380504 380912

I.e., the (exact) same objects appear in each list: only pointers have
been copied. I believe the semantics of the language _require_ the
implementation to copy just a reference (pointer) for mutable objects,
but allow reference or value copying for immutable objects (but that the
current implementation usually (always?) just copies a pointer even then
-- and that that's unlikely to change in future implementations).

but-as-always-deferring-to-guido-for-the-truth-ly y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp