Python's Reference And Internal Model Of Computing Languages
Jürgen Exner
jurgenex at hotmail.com
Fri Feb 5 11:48:29 EST 2010
David Thole <dthole at gmail.com> wrote in comp.lang.perl.misc:
>I read this....and am a tiny bit confused about the actual problem.
>
>It's not exactly complex to realize that something like:
>a = b = array
>that a and b both point to the array.
???
What are you talking about? First of all you should post actual code,
not pseudo-code because pseudo-code leads to misunderstandings. Did you
mean
@a = @b = @array
Second what do you mean by "pointing"? That is a very ambiguous term. if
you do the assignment as written above then @a and @b will be _copies_
of @array. If you want two additional references to the same array
insted then you have to create that reference first and assign that
reference to $a and $b instead of copying the array, see "perldoc
perlref" for details. And remember, references are scalars, no matter if
they reference other scalars or arrays.
>Logically speaking, I'm not sure how one could assume that the same
>assignment would yield a and b point to the same duplicate array. If
Now what? The same array or a duplicate array? Two very different and
mutually exclusive things.
>that was the case, why not do:
>a = array..
>b = array..
Which, after correcting the obvious syntax errors is the same as the
code above.
>I know with what you were complaining about a few days ago, .clear makes
>perfect sense. If a and b point to the same array, clear should clear
They don't point, they are copies. And what do you mean by "clear"?
>both arrays. Again, if you didn't want that to happen, create a
>duplicate array.
But that is what that code above does. If you want references then
create references.
jue
More information about the Python-list
mailing list