On 09/06/2016 11:03, Marko Rauhamaa wrote:
Antoon Pardon <antoon.par...@rece.vub.ac.be>:
Your challenge, shows that you don't fully understand what reference
variables are. The behaviour you see in Pascal, doesn't depend (alone)
on the parameter being a reference parameter. It also depends on the
fact that the assignment in pascal mutates the variable that is
assigned to. Variables are references if they are aliases, so that if
you mutate through one alias, the mutation is visible through other
aliases. So your challenge comes down to expecting me to mutate
something by means that in python don't allow mutation.
I think bringing Pascal in this discussion is only confusing matters.
Let me repeat the abstract Python data model I gave a couple of days
back:
- there are labeled *pegs* ("variables")
- there are *puppies* ("objects")
- each peg has one *leash* hanging from it
- each leash is tied to a puppy
- each puppy can have zero one or more leashes tied to it
- some puppies can hold leashes in their *mouths*
- some puppies can take hold of new leashes and let go of leashes
I'm not joking. Everybody is arguing about preconceived notions tied to
terminology. The peg-leash-puppy model is accurate and extensive.
We can now give semantics to Python's execution model. For example,
- every rvalue expression evaluates to a leash
- the lvalue expression identifies a peg or a mouth
- the assignment statement hangs a leash on a peg or in a mouth
And to implement swap() you need a leash that can be tied to a peg.
(Here, I'm assuming 'hanging from' and 'tied to' suggest that a leash is
uni-directional. But it's possible to imagine that a different part of a
peg is used to hang an out-going leash, compared to tying an incoming
one. Just like the puppies have necks to tie incoming leashes to (via
collars to avoid cruelty) and mouths for out-going ones.)
--
Bartc
--
https://mail.python.org/mailman/listinfo/python-list