An alternative approach to bound methods

Alex Martelli aleaxit at yahoo.com
Thu Feb 22 11:14:05 CET 2001


"Marcin 'Qrczak' Kowalczyk" <qrczak at knm.org.pl> wrote in message
news:slrn998h48.1te.qrczak at qrnik.zagroda...
    [snip]
> I would definitely change that and let all scopes nest, classes too.
>
> A recursive function should be able to refer to itself in the same
> way no matter if it's defined at the top level, in another function,
> or in a class. The first two cases were unified in 2.1b2, but the
> third has not been unified.

I *STRONGLY* disagree, because in the third case, AND IN IT ONLY,
inheritance and overriding come into play!!!

class X:
    def foo(self, N):
        if N>23: return 1+2*self.foo(N/2-4)
        else: return N/7

_This_ recursively-defined function IS subject to overriding -- I
know this, and I see it very clearly, because of the "self.foo".

It would be just as clear and explicit that overring is NOT
supported if I used X.foo in the recursive call.  _Normally_
the potential for polymorphism and overriding IS desired, of
course, but it's important to be able to explicitly express
"...and here, strangely enough, NO overriding predicted".

But what should it mean if just "1+foo(N/2-4)" was coded, in
your "all scopes nest" ideal?  Would you thus facilitate the
EXCEPTIONAL case, in which X.foo is wanted, to the detriment
of the NORMAL case, in which self.foo is wanted?  Or have
some C++-like black magick, to have foo mean self.foo...?!

Thanks, but, NO thanks.

Nesting is for the birds!-)


Alex






More information about the Python-list mailing list