Arthur wrote: > > >>> -----Original Message----- >>> From: [EMAIL PROTECTED] >>> [mailto:[EMAIL PROTECTED] On Behalf Of Arthur >>> Sent: Saturday, March 18, 2006 1:39 PM >>> To: 'Scott David Daniels'; [email protected] > >>> I don't understand, really, the distinction >>> between a vector expressed as a list and a vector expressed >>> as a tuple, from the concept of a complex number in mutable >>> form, and one in immutable form. >>> >>> If you feel like trying to help... > > > Put another way, if I take the PyPy implementation of the complex primitive, > and comment out the 2 property lines that restrict the write to real and > imag - and instead of calling it a primitive I call it a class. And I use > the class as such - where have I gone wrong? > > Art
OK, so as I said in my over-long thing, immutable types have an exciting property that you can't really tell aliases from copies. This makes Python's call method behave a lot like "call-by-value" -- a good thing, since call-by-value is easy to analyze (both for machines and humans). With mutables, you have the question of "caller-saves" or "callee-saves" in function calls. Caller-saves makes a copy to do the call with, and callee-saves makes a copy on function entry (at least for those args for which there will be mutation). Typically, a lot of effort (either by the compiler or the programmer) is expended to keep all of this copying to a minimum. With immutables, you needn't do any of the bookkeeping. It is not that you have gone terribly wrong; it is that you have opened the lid on a large class of avoidable problems. If you look at Java's strings (as I remember -- it has been forever since I studied Java at all), you will find they are mutable. You also find that Java code copies strings a _lot_, just to be safe against lower- level mutation. Your primitive complex (the mutable one) also could not be used as a dictionary key except by identity, which would not allow rapid access. --Scott David Daniels [EMAIL PROTECTED] _______________________________________________ Edu-sig mailing list [email protected] http://mail.python.org/mailman/listinfo/edu-sig
