cell object dereferencing

Jan Decaluwe jan at jandecaluwe.com
Tue Dec 9 15:41:08 EST 2003


Terry Reedy wrote:
> "Jan Decaluwe" <jan at jandecaluwe.com> wrote in message
> news:3FD5FD4A.9060406 at jandecaluwe.com...
> 
>>Is there a way to dereference a cell object (that is, get
>>the object that it references to) in Python?
> 
> 
> [Background: a cell is an undefined internal implementation object used to
> make nested scoping work as advertised.  One might think of it as a means
> for persisting cross-scope name-binding of objects in intermediate nested
> scopes of nested functions.  Alternatively, a cell is 'persistent read-only
> shadow of an outer local'.  For nested functions that access intermediate
> locals, .func_closure is a tuple of 'cells'.]
> 
> Yes and no, depending on what you mean be 'dereference'.  Within the nested
> function, you 'dereference' the variable the same way you do any bound
> ame  -- write it!  Outside the function, where the variable has no
> conceptual existence, you can grab a cell from the func_closure tuple, but I
> know of no way to access its value.

This is what is mean - so I guess the answer is no.

>Both repr() and str() return a <cell at
> xxx: type at yyy> description. If you want a globally accessible value, use
> a global variable.

The background is that I am writing a small compiler that translates a 
(small) subset of Python into another language. I would like to be able to
support free variables as they are likely to be useful in the kind of
code I'm targetting. However, I need to be able to inspect the corresponding
objects for their type etc. Conceptually this should be possible, just as
with globals and locals of functions and frames, but in practice it seems
it isn't - a real pity for which I hope to find a workaround.

Regards, Jan

-- 
Jan Decaluwe - Resources bvba - http://jandecaluwe.com
Losbergenlaan 16, B-3010 Leuven, Belgium
    Bored with EDA the way it is? Check this:
    http://jandecaluwe.com/Tools/MyHDL/Overview.html





More information about the Python-list mailing list