Nested function scope problem

Antoon Pardon apardon at forel.vub.ac.be
Tue Aug 1 13:44:54 EDT 2006


On 2006-08-01, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
> On Tue, 1 Aug 2006 11:12:31 -0300, Gerhard Fiedler <gelists at gmail.com>
> declaimed the following in comp.lang.python:
>
>> There's maybe a point in comparing Python variables to C pointers. But it
>> lacks in the respect that a C programmer is used to modify memory locations
>> through pointers. A Python programmer isn't used to modify memory locations
>> in the first place, and simple objects don't get modified at all. There's
>> no Python equivalent to "int*p=345; *p++;". (There's no need for that in
>> Python; I'm not saying this shows a superiority of C. It just shows a
>> different concept of what "variable" means.)
>>
> 	Python
>
> 		c = c + 100
>
> 	pseudo-C (where I use _p to indicate explicit pointer; and all data
> objects are a structure of the form: int ref_count; <object type> data)
>
> 	scratch_p = malloc()	
> 	scratch_p->data = c_p->data + 100
> 	scratch_p->ref_count = 1
> 	c_p->ref_count--
> 	if !c_p->ref_count
> 		free(c_p)
> 	c_p = scratch_p
>
> -------
> 	b = a
> is
> 	b = a
> 	b->ref_count++
>
>
> 	 
>> For me, the point of this discussion was that it makes sense to look at it
>> /differently/. Once you've done that, there's no problem in continuing to
>> use the (vaguely defined) term "variable". 
>> 
>
> 	Think the above is "different" enough <G>

The above are implementation details. 

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;

That look different enough from just "c = c + 100". So maybe C
has no variables either.

-- 
Antoon Pardon



More information about the Python-list mailing list