[Tutor] Making Doubly Linked List with Less Lines of Code.

Dave Angel davea at davea.name
Fri Jan 2 19:40:19 CET 2015


On 01/02/2015 12:57 PM, Alex Kleider wrote:
> On 2015-01-01 17:35, Alan Gauld wrote:
>
>> Repeats replicates the reference to the object but
>> does not create a new object.
>
> This part I can understand but, as Steven has pointed out,
> this behaviour changes if the object being repeated is immutable.
> Why would one get a new object (rather than a new reference to it)
> just because it is immutable?  It's this difference in behaviour
> that depends on mutability that I still don't understand even though
> Steven did try to explain it to me:
> """
> If the list items are immutable, like ints or strings, the difference
> doesn't matter. You can't modify immutable objects in-place, so you
> never notice any difference between copying them or not.
> """

You have it backwards.  The behavior doesn't change between mutable and 
immutable, the visibility of the behavior changes.

If the object is immutable, you can't tell it hasn't been copied.

An "assignment" does not create a new object, immutable or not.  it 
simply binds the left side to the object on the right.

a = x

does not copy x, no matter what type it may be.  It simply binds a to 
the object.

-- 
DaveA


More information about the Tutor mailing list