nested classes

Bjorn Pettersen BPettersen at NAREX.com
Mon Jun 18 19:40:55 EDT 2001


> From: Mats Wichmann [mailto:xyzmats at laplaza.org]
> 
> On Mon, 18 Jun 2001 13:23:33 -0500, Stefan Seefeld
> <seefeld at sympatico.ca> wrote:
> 
> >gbreed at cix.compulink.co.uk wrote:
> >
> >> > What am I doing wrong ? The above is possibly a bit driven
> >> > by my C++ programming style. What is the python way of doing
> >> > this ?
> >> 
> >> You can get that to work in C++?  It looks strange to me, I'm
> >> sure you can't be trying to do what you think you're trying to
> >> do.  This is the nearest I can think of that works:
> >
> >uh, what do *you* think that I'm trying to do, then ? :)
> >
> >What I'm arguing about is a matter of name resolution. I sure
> >can open a scope 'A' in C++, insert a new scope 'B' into it,
> >and from within that access other symbols declared in scope 'A'.
> >In fact, I don't need to qualify them (i.e. 'foo' instead of 'A::foo'
> >for any symbol 'foo' in the scope 'A' is just fine) if I'm inside
> >that scope, no matter how deeply nested (of course, as long as there
> >are no ambiguities).
> 
> Java and C++ are compiled.  The class definition is instructions to
> the compiler, and can be self-referential, because the /reference/ is
> not going to happen until the class is loaded - no inconsistency.  Not
> so for Python, the class definition is code that is actually run to
> build the class object, and before that object has been built, there's
> nothing to refer to yet, as Alex said.

But that's an implementation detail only, since it works perfectly for
functions:

  def foo():
      foo()

insert-definition-of-letrec-vs-let-here'ly y'rs
-- bjorn




More information about the Python-list mailing list