Copy constructors

Gareth McCaughan Gareth.McCaughan at pobox.com
Sat Aug 18 17:30:13 EDT 2001


Guido van Rossum wrote:

> While I probably introduced this myself (pickle uses it), I have one
> reservation.  Assignment to self.__class__ is unique to Python -- it's
> not an idiom one can easily translate to other languages.  It's also a
> relatively new Python feature (I don't even know if Jython supports
> it).

Something very like it is possible in Smalltalk (#become:) and
in Common Lisp (CHANGE-CLASS). I suspect it's possible in Perl,
but I'm too lazy to check :-).

(It's possible that I have the name of the Smalltalk method
wrong. There definitely is one, though.)

Certainly, class-changing isn't possible in much less dynamic
languages like C++ and Java, but then lots of things you can do
in Python are impossible (or at least much harder) in much less
dynamic languages.

-- 
Gareth McCaughan  Gareth.McCaughan at pobox.com
.sig under construc



More information about the Python-list mailing list