why cannot assign to function call

Terry Reedy tjreedy at udel.edu
Sun Mar 15 02:45:34 CET 2009


Aahz wrote:
> In article <mailman.952.1235850376.11746.python-list at python.org>,
>  <rdmurray at bitdance.com> wrote:
>> I think this is the key point.  I am an experienced Python programmer,
>> and I had to think long and hard about what you were saying, Mark, in
>> order to understand how it applied to Python.  I think this means that
>> your model and/or your level of abstraction is not "natural" when trying
>> to understand Python programs, and I think I may have figured out why.
> 
> Good job!  I'll just add one little bit to your excellent rebuttal:
> 
>> Assignment in Python changes a mapping (mutates a namespace object). In
>> this case the mapping being changed is the local function's namespace
>> mapping.  We can't affect the caller's namespace mapping, because (in
>> this function) we don't have access to the caller's namespace object.
>> So I would diagram it like this:
>>
>>         y (in global env.)  -----> 'virgin'
>>
>>         x (in function 'test')  ----> 'clobbered'
> 
> Although you later make clear that this model works well with lists, too,
> I personally find it easier to separate the concept of "name" (which is
> strictly the set of legal Python identifiers) with the more general
> concept of "target".  Consider this:
> 
>>>> L = [1, 2, 3]
>>>> L[1:1] = ['foo', 'bar']
> 
> What do you call ``L[1:1]``?

I call that a collection slot.

>  I call that a target (and in fact, so do the Python docs).

Targets encompass both names and slots.




More information about the Python-list mailing list