why cannot assign to function call
Marc 'BlackJack' Rintsch
bj_666 at gmx.net
Mon Jan 5 11:37:53 CET 2009
On Sun, 04 Jan 2009 20:03:11 -0600, Derek Martin wrote:
> On Sat, Jan 03, 2009 at 10:15:51AM +0000, Marc 'BlackJack' Rintsch
>> On Fri, 02 Jan 2009 04:39:15 -0600, Derek Martin wrote:
>> What's the difference between Python and Java or C# here!? Or are they
>> also "BIZARRE"!?
> I am happily ignorant of C#. As for Java, take the following code:
> a = 6;
> a = 5;
> In Python, when you execute the equivalent code, it causes two different
> objects to spring into existence, the first of which may be cleaned up
> by the GC (except that since we're using small integers, that's not
> likely to happen). Unless I'm misinformed (which is very possible, my
> experience with Java has been extremely limited) in Java that's not the
> case... the storage is allocated to the name a when you execute its
> declaration, and the *same storage* is reused upon subsequent
> That behaves exactly like named bins.
So does the equivalent in Python. Or to see it the other way: In both
languages it *behaves* like (re)binding the name `a` to two different
objects. So it is an implementation detail. Even a Python
implementation could reuse the same memory location to store the two
>> > And for that matter, it's pretty unintuitive generally.
>> Names and objects are quite "natural" IMHO. There are many real world
>> objects which we attach one or more names to, or refer to in sequences
>> like "please give me the third book on that shelve" (``shelve``).
> Indeed, but the way we assign names to them does not behave as it does
> in Python.
In what way?
>> I think the "bin model" is more complex because you don't just have a
>> name and an object but always that indirection of the "bin".
> I cheerfully disagree. :) "Named bins" is essentially how algebra
No it isn't. Mathematics is about binding names and not about putting
values into bins. And a mathematical variable can't be rebound once you
assigned a value to it. The "intuitive" model for people with a math
background would be that of functional languages like Haskell, which is
even more strange for people used to "named bins" than the Python, Java,
Ruby, … approach.
> and how several generations of computer languages, not to mention
> the actual machine language those generated, behaved, before the current
> crop. Those interpretations came first, because, much as in the
> evolution of any other science, that was the model which was most
> intuitive or easily explained.
In terms of the underlying machine, but that is exactly what I meant by
the additional indirection of the bins. You just have to drag the low
level named bins into the explanation because it is an implementation
detail of the languages.
And there where always languages that use a model like Python parallel to
the "named bins languages", it is nothing new.
Marc 'BlackJack' Rintsch
More information about the Python-list