From: Bruce S. <Bru...@nc...> - 2004-08-23 00:33:33
|
I think I see. Thanks for the further analysis. So two wrongs don't make (or shouldn't have made) a right. Bruce Sherwood Jonathan Brandmeyer wrote: > On Sun, 2004-08-22 at 16:38, Bruce Sherwood wrote: > >>I ran Jonathan's test routine in pre-Boost and Boost versions of >>VPython. In the pre-Boost version the behavior is NOT what Gary and >>Jonathan describe. In the pre-Boost version the two forms of the update >>statement work exactly the same in Jonathan's test routine. The original >>Visual deliberately did something like this: >> >> sphere(pos=a) was treated as though it were written as >> sphere(pos=vector(a)) > > > Current VPython does this too for all of its built-in attributes. The > problem stems from the use of user-defined attributes, for which there > is no way to force a copy that will work for all Python data types > (copy.copy() is close, but doesn't work for everything). > > Old visual.vector did not provide the in-place operators (+=, *=, and > friends), which forced the interpreter to emulate them incorrectly. > > Python programmers must be aware that all Python variables are > references. Consider this program, which also incorrectly assumes that > '=' makes a copy: > > from visual import * > spheres = [] > velocity = vector(0,0,0) > spheres.append( sphere( v=velocity)) > spheres.append( sphere( v=velocity)) > > > twice = 2 > while twice: > print "before iteration:" > for i in spheres: > print i.v > > ctr = 0 > for i in spheres: > print ctr > ctr += 1 > print "before:", i.v > i.v.x += 1 > print "after", i.v > > twice -= 1 > > -Jonathan > > > > ------------------------------------------------------- > SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media > 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 > Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift. > http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285 > _______________________________________________ > Visualpython-users mailing list > Vis...@li... > https://lists.sourceforge.net/lists/listinfo/visualpython-users |