Pass by reference ?
Michael Hudson
mwh21 at cam.ac.uk
Wed Apr 5 11:33:26 EDT 2000
"Robert W. Cunningham" <rcunning at acm.org> writes:
> Python can either 1) Pass a reference to the original data, or 2) Pass a
> reference to a copy of the original data. At no time does Python "pass
> the data" directly (as in the "C" sense of, say, a register variable),
> since everything is treated as though it were (in some sense) an object
> (even if not "really" an object of the First Water).
>
> Which, when mapped to conventional CS terminology (as extended by Moi),
> becomes "Pass By Reference" and "Pass By Clone".
>
> Clearly, "Pass By Clone" makes the original data item completely
> inaccessible within the called function (ignoring bytehacks for now),
> and thus immutable. For me, this helps to clarify things, since Python
> literally passes only references.
>
> But, of course, that depends: Is this a clarification, an obfuscation,
> or Just Plain Wrong?
I'm not sure I'm understanding you, but I'd say "Just Plain Wrong".
Python never ever copies anything when you pass it as an argument to a
function - it's just that sometimes the things you pass are immutable
- which is when it looks like call by value - and sometimes they're
mutable - when it looks a bit like call by reference.
Try to cast Python semantics in terms of what other langauges do is
confusing - I've just successfully confused myself trying (as you
could see if you could read my kill-ring) - and is hence to be
considered bogus, because Python's semantics are actually extremely
straightforward.
HTH,
M.
--
well, take it from an old hand: the only reason it would be easier
to program in C is that you can't easily express complex problems
in C, so you don't. -- Erik Naggum, comp.lang.lisp
More information about the Python-list
mailing list