[Tutor] list as a first class citizen in python?

Karthik Gurumurthy karthikg@aztec.soft.net
Wed, 26 Dec 2001 12:14:17 +0530


I found this quote on the web..regarding python...

>>>>>>>
    Because everything is a reference, and there's no way to dereference
    that reference, it turns out that there is no trivial way to copy
    a list!  This fails:
	x = [1,2]
	y = x
    Because you don't get a new list there, just a copy to an
    old one.  Suggested work-arounds include
	y = x[0:]
	y = x[:]
	y = x + []
	y = x * 1
    This forces people to think about references, again.
    So much for lists being first class citizens!  Compare
    this with Perl's
	@x = (1,2);
	@y = @x;
    Or even with references:
	$x = [1,2];
	$y = [ @$x ];
    or
	@y = @$x;
>>>>>>>>

what's wrong with working with a reference.
can someone explain the argument here?
java does a similar thing. In java i would do a clone() to get a copy of an
arraylist and in python i will

import copy
copy.deepcopy(l)

if something is a first class citizen , should it support "copying" using
simple assignments ? / how are first class citizens expected to behave ? :-)

thanks,
karthik.