However, A=3*A creates a new vector (0,3,0) and binds that to A,
leaving the original unchanged. What happens of you use A*=3 or A.y=3?
Robert
在 2009-9-14,上午11:38,Bruce Sherwood <Bru...@nc...> 写到:
> Thanks for the additional background, Craig. It's good to have a
> card-carrying
> computer scientist commenting on the issues!
>
> Your point about updating a bunch of Visual objects however doesn't
> work,
> because the setters for Visual vector attributes like pos or axis
> make new
> vectors. This explains for example why you can write as a shorthand
> pos=(1,0,0)
> instead of pos=vector(1,0,0); a vector is constructed out of the
> triple.
>
> Here is a routine that shows the (non)effect:
>
> A = vector(0,1,0)
> arrow(pos=(0,0,0), axis=A)
> arrow(pos=(1,0,0), axis=A)
> scene.mouse.getclick()
> A = 3*A
>
> After clicking, the arrows don't get longer, because axis=A is
> basically
> axis=vector(A).
>
> In any case, it would be a rare circumstance where you wanted some
> vector
> attribute of lots of objects to be the same, and to change together.
>
> Bruce Sherwood
>
> Craig Struble wrote:
>> It should be pointed out that many object oriented languages share
>> this behavior. Java behaves the same way, for example. Many others
>> have pointed out the difficulties in copying objects (deep vs.
>> shallow
>> copies) and bigger problems for copying arise when there are circular
>> references, which are common for complex data structures (e.g.
>> general
>> graphs).
>>
>> The object reference behavior is useful when implementing some kinds
>> of data structures when you need a "trailing pointer" for updates.
>> Lots of linked list implementations use this approach. It's atypical
>> to do this in Python since it has a very rich collection of data
>> structures already implemented, but it can be useful.
>>
>> I would guess in VPython, this behavior could make it easier to
>> update
>> the positions or movements of a large group of visual objects. If
>> they
>> all refer to the same point or vector, change that vector and all the
>> objects change accordingly. It would be nice to make a single update
>> instead of having to looping over each object, which would probably
>> be
>> slower.
>>
>> Craig
>>
>
> ---
> ---
> ---
> ---------------------------------------------------------------------
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
> 30-Day
> trial. Simplify your report design, integration and deployment - and
> focus on
> what you do best, core application coding. Discover what's new with
> Crystal Reports now. http://p.sf.net/sfu/bobj-july
> _______________________________________________
> Visualpython-users mailing list
> Vis...@li...
> https://lists.sourceforge.net/lists/listinfo/visualpython-users
|