Nested function scope problem

Antoon Pardon apardon at forel.vub.ac.be
Wed Aug 2 09:09:26 EDT 2006


On 2006-08-02, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On 1 Aug 2006 17:44:54 GMT, Antoon Pardon <apardon at forel.vub.ac.be>
> declaimed the following in comp.lang.python:
>
>> Suppose I write a C-interpreter and then would translate a statement
>> like "c = c + 100" into actions the interpreter would have to take in
>> order to excute that statement. Something like:
>> 
>>   c-addr_p = GetAddress("c");
>>   c-value = *c-addr_p;
>>   sum = c-value + 100;
>>   *c-addr_p = sum;
>>
> 	If this is what your interpreter generates/executes for a C-language
> assignment, then the source language is no longer C...

How do you come to that decision?

> After all, Python's most common implementation IS in C.
>
> 	In C, the difference between "c" as a pointer, and "*c" as what it
> points to is explicitly exposed to the user... The two views can be
> separately manipulated. "c" as a variable can be manipulated -- c++
> changes c to "point to" an object (of the type of "c") that is presumed
> to follow the existing object -- whether such exists or not.
>
> 	Python does not expose that to the user... You have a name and you
> have an object. The name exists, or it doesn't, independent of the
> object. Not in C -- while the object may not exist, the name, to be used
> at all, has to exist and has storage space assigned to it; storage the
> programmer is able to manipulate without an object.

And how is this all relevant in deciding that the source language for
the above interpreter actions isn't C? What the interpreter does is
the following:

  Get the addres of the variable c
  Get the value that is at that address.
  Add 100 to this value
  Store the new value at that address.

Please explain what is wrong in this sequence of actions
for an interpretation of the C statement: "c = c + 100;"

-- 
Antoon Pardon



More information about the Python-list mailing list