why cannot assign to function call

Aaron Brady castironpi at gmail.com
Fri Jan 9 12:15:57 CET 2009


On Jan 9, 4:01 am, Steven D'Aprano <st... at REMOVE-THIS-
cybersource.com.au> wrote:
> On Thu, 08 Jan 2009 18:33:50 +0000, Mark Wooding wrote:
> > [Steven's message hasn't reached my server, so I'll reply to it here.
> > Sorry if this is confusing.]
>
> > Aaron Brady <castiro... at gmail.com> wrote:
> >> On Jan 8, 1:45 am, Steven D'Aprano
> >> <ste... at REMOVE.THIS.cybersource.com.au> wrote:
> >> > On Wed, 07 Jan 2009 10:17:55 +0000, Mark Wooding wrote:
>
> >> > > The `they're just objects' model is very simple, but gets tied up
> >> > > in knots explaining things.  The `it's all references' model is
> >> > > only a little more complicated, but explains everything.
>
> >> > But it *over* explains, because it implies things that "everybody
> >> > knows" about references in other languages that aren't true for
> >> > Python.
>
> > I addressed this elsewhere.  Summary: `pass-by-reference' is a different
> > thing to `all you manipulate are references':
>
> You know, I've written a fair bit of Python code over the years, and I've
> never manipulated a reference *once*. Ints, strings, floats, lists,
> tuples... but references? Never.
snip
> That's why we should try to keep the different layers of explanation
> separate, without conflating them. Python programmers don't actually flip
> bits, and neither do they manipulate references. Python programmers don't
> have access to bits, or references. What they have access to is objects.
snip
> >> > How do we deal with anonymous objects in your model?
> > What I am pretty sure of is that references are going to have to enter
> > the picture at some point, because other models get too complicated.
>
> Well, I dare say that at *some* point all models are insufficient. The
> map is not the territory, and there's always something that gets left
> out. But I think your model with strings is more complicated: robots,
> sticky Blu-Tack, string that you can't touch or see, and so forth.
> Compared to that, TARDIS technology enabling objects to be in two places
> at once is remarkably straightforward. Despite it being physically
> unrealistic, it's logically simple.
>
> --
> Steven

Possible compromise.  You can think of functions as mutation-only.
You pass the object, and it gets a new (additional) name.  The old
name doesn't go in.  </compromise>

Regardless, IMO, references don't add any explanatory power; they just
make you feel cocky that you know what they are.

M: If 'fun()' returned a reference, you would be able to assign to it.
m: You can't assign to it.
C: It doesn't return a reference.

-- Why can't I assign to a function call?
-- Python variables are references only.
-- Ok, why can't I assign to a function call?
-- [Explanation Steven is trying to give.]

In other words, Mark and Joe, cut to the chase.  You're shirking.



More information about the Python-list mailing list