In IronPython 2.0, when I replace a Point object in a list using assignment, a 
copy of the Point object is used to replace the original list element rather 
than the original Point itself. This does not happen with user-defined objects. 
It also does not happen with Point objects in IronPython 1.1.

IronPython 2.0 (2.0.0.0) on .NET 2.0.50727.3053
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference("System.Drawing")
>>> from System.Drawing import *
>>>
>>> class C(object): pass
...
>>> def test1():
...     p1 = C()                # Create two objects
...     p2 = C()
...     l = [p1]                # Put one in a list
...     print id(l[-1]), id(p2) # Print ids of object in list (p1) and p2
...     l[-1] = p2              # Replace p1 with p2 in list
...     print id(l[-1]), id(p2) # Print ids of object in list and p2
...
>>> def test2():
...     p1 = Point(1,2)         # Create two Points
...     p2 = Point(3,4)
...     l = [p1]                # Put one in a list
...     print id(l[-1]), id(p2) # Print ids of Point in list (p1) and p2
...     l[-1] = p2              # Replace p1 with p2 in list
...     print id(l[-1]), id(p2) # Print ids of Point in list and p2
...
>>> test1()
43 44
44 44
>>> test2()
45 46
47 46   # The id of the Point before and after adding to the list is different
>>>

Here is the same program in IronPython 1.1

IronPython 1.1 (1.1) on .NET 2.0.50727.3053
Copyright (c) Microsoft Corporation. All rights reserved.

<snip>

>>> test1()
43 44
44 44
>>> test2()
45 46
46 46   # The id of the Point before and after adding to the list is the same
>>>

... or am I missing something.


_________________________________________________________________
Send e-mail faster without improving your typing skills.
http://windowslive.com/online/hotmail?ocid=TXT_TAGLM_WL_hotmail_acq_speed_122008
_______________________________________________
Users mailing list
Users@lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to