What is a function parameter =[] for?

Laura Creighton lac at openend.se
Thu Nov 19 20:00:02 EST 2015


In a message of Thu, 19 Nov 2015 16:36:17 -0800, Ned Batchelder writes:
>On Thursday, November 19, 2015 at 7:28:44 PM UTC-5, Steven D'Aprano wrote:
>> On Fri, 20 Nov 2015 05:50 am, BartC wrote:
>> 
>> 
>> > I said that Python's "=" does a very shallow copy. And I stated that in
>> > A=B, something of B must be copied into A.
>> > 
>> > I (and probably others) would like to know why none of that is correct.
>> > But I suspect I'm not wrong.
>> 
>> Nothing of B is copied.
>
>I think we are stuck in a simple terminology conflict here.  There is something
>of B copied.  The name B refers to a value.  In CPython, that reference is a
>pointer.  That pointer (the memory address) is copied from B to A.
>
>Nothing of "B's value", that is, the object B is referring to, is copied. But
>there is something about B (the pointer to its value) that is now also something
>about A, because A also has that pointer.
>
>--Ned.

In PyPy we do this too.
But we don't copy a memory-address pointer.
We have a moving garbage collector, and no objects are in any way
guaranteed to be at their last memory address.

We copy a thing that, when you ask it nicely, spits out "where the hell
is the object right now,  because I want to modify it."

But this thing is in no way tied to any particular place in any DRAM.
It hits PyPy at an abstraction layer above that of 'we write 1s and 0s
here' so if you want to implement python on a message passing system
implemented by carrier pigeon, we could do this.  It would be slow,
however. :)

Laura



More information about the Python-list mailing list