why cannot assign to function call

Aaron Brady castironpi at gmail.com
Mon Dec 29 20:46:36 EST 2008


On Dec 29, 6:06 pm, Miles <semantic... at gmail.com> wrote:
> On Mon, Dec 29, 2008 at 1:01 AM, scsoce <scs... at gmail.com> wrote:
> > I have a function return a reference, and want to assign to the reference,
> > simply like this:
> >>>def f(a)
> >         return a
> >    b = 0
> >   * f( b ) = 1*
> > but the last line will be refused as "can't assign to function call".
> > In my thought , the assignment is very nature,  but  why the interpreter
> > refused to do that ?
>
> Here's some links to help you better understand Python objects:
>
> http://effbot.org/zone/python-objects.htmhttp://effbot.org/zone/call-by-object.htm
>
> The second one is a bit denser reading, but it's important to learn
> that Python's approach to objects and "variables" is fundamentally
> different from that of C/C++.  In the example below, there's no way in
> the Python language* that bar() can change the value of b, since
> strings and numbers are immutable.

On a technicality, to avert a flaming, "change the value of 'b'" is an
ambiguous phrase.  There are two interpretations of "change what 'b'
refers to" and "change what 'b' refers to".  Even in spoken language,
I don't think that emphasis can resolve them either.

One means, 'make a change in the world, in the actual configuration of
such and such actual matter.'  The other means, 'update the axioms the
speaker is using to communicate to the listeners.  (Such and such will
no longer refer to such and such; it will refer to such and such;
accept this and reject that.)'  To make an observation, reference is a
purely linguistic phenomenon.

I, for one, am at a loss for how to disambiguate it.  I'm open to
suggestions.



More information about the Python-list mailing list