why cannot assign to function call
Steven D'Aprano
steven at REMOVE.THIS.cybersource.com.au
Wed Jan 14 03:43:17 EST 2009
On Tue, 13 Jan 2009 23:06:58 +0000, Mark Wooding wrote:
> I'm going to move away from the formal semantics stuff and try a
> different tack. Here's what I think is the defining property of
> pass-by-value (distilled from the formal approach I described earlier,
> but shorn of the symbolism):
>
> The callee's parameters are /new variables/, initialized /as if by
> assignment/ from the values of caller's argument expressions.
Well, that's one way of looking at it, I guess. The problem is that when
I do this:
x = "something" # just an example, not necessarily a string
y = x
Does the line y=x create a new variable? Depends on what you mean by
variable. If you mean a new name, symbol or whatever, then obviously yes.
But if you mean a new value, namely the string "something", then not
necessarily. In Pascal (and C?) those bytes are copied, giving two
independent values which just happen to be equal. In Python, both x and y
refer to the same string, and I choose the term deliberately. See, I'm
not *entirely* against the use of referring to references, when
appropriate. I think we just differ on when we think it's appropriate.
Which I guess brings us back to your earlier assertion (I think it was
you) that people aren't confused about argument passing, they're confused
about assignment.
[...]
> But! (you claim) ...
>
>> Python simply can't be pass-by-value, because it doesn't behave like
>> pass-by-value in other languages (particularly C and Pascal).
>
> Ah! (say I) but assignment in C and Pascal looks different from the way
> it looks in C
I'm sorry, that confuses me. Assignment in C looks different from the way
it looks in C? I guess the second C should be Python.
> -- and in exactly the same way that argument passing looks
> different. And there, I think, I'm going to rest my case.
>
> I'm sorry I took so long to distill these thoughts. Thank you for
> putting up with my theoretical meanderings on the way.
And thank you for not kill-filing me when tempers were getting short.
--
Steven
More information about the Python-list
mailing list