[Python-ideas] binding vs rebinding

spir denis.spir at free.fr
Fri Feb 6 10:43:40 CET 2009

Le Fri, 06 Feb 2009 08:31:58 +1100,
Ben Finney <ben+python at benfinney.id.au> a écrit :

> > I wonder why there is no difference in syntax between binding and
> > rebinding. Obviously, the semantics is not at all the same, for
> > humans as well as for the interpreter:  
> > * Binding: create a name, bind a value to it.
> > * Rebinding: change the value bound to the name.  
> That's not obvious. The semantics could just as well be described as:
>   * Binding: bind this name to that value.
>   * Rebinding: bind this name to that value.

You are right do describe it like that. I agree that the point of view is not wrong. However,

* At the interpreter level, as far as I know, rebinding does not create the name like if it was unknown. (Note that a similar issue happens with dicts.)
* At the programmer level, changing the value associated to a name is really a different action than introducing and giving an initial value to a new symbol. For me, *this* is the relevant point: even if the language would behave "behind the scene" the same way in both cases. This is implantation concern.

A pertinent objection has been raised already in the case of loops:

for item in container:
	# temp symbol
	foo = func(item)
	# process

Conceptually, there is a foo for each item. Obviously, we cannot express that properly, because the loop's body is the same for each iteration. The issue here lies in the fact that a loop does not introduce a local namespace, while this is precisely what we *mean* when defining such as utility variable as foo. 
In other words: there is a distortion between language semantics and modelizing semantics.

la vida e estranya

More information about the Python-ideas mailing list