At 2:26 PM -0500 10/29/02, Guido van Rossum wrote: > > >Correct. I don't see this as a huge limitation -- all "autoload" >> >features that I'm familiar with (Emacs, Tcl; how about Perl?) require >> >you to know at least the auto-loaded names in advance. (Also in my >> >defence you only mentioned the cost of unpickling everything as an >> >argument. :-) >> >> Perl doesn't require it. If a method call is made but that method >> name doesn't appear in the object's inheritance hierarchy, perl walks >> up the tree looking for a method named AUTOLOAD and if it finds one >> calls that. The AUTOLOAD method then has the opportunity to do >> something--satisfy the call, dispatch to a parent class, or pitch a >> fit. It's valid for an AUTOLOAD method to satisfy the request without >> instantiating a method for it. (In which case the next invocation of >> that method will end up back in AUTOLOAD) > >Um, as long we're doing *method* lookup, Python's __getattr__ can do >all that. Sorry--it's a twisty conversation of little passages. I got somewhat turned around. > > Works for subroutines too, though the hierarchy isn't supposed to be >> walked for those. (Older versions of perl would do it, but that's >> been deprecated) > >OK, so if there's a global AUTOLOAD and no global x, looking for x >will call AUTOLOAD to satisfy x, right? Python doesn't do this, and >this is what the "hookable namespace" feature is aiming at. If there's an AUTOLOAD in a package, no X in that package, and you call X, then that package's AUTOLOAD will get called instead, yes. So if you had: print(Foo::Bar()); to print the output of the subroutine Bar in the package Foo, and there was no subroutine Bar in the package Foo but there *is* a subroutine AUTOLOAD in the package Foo, then Foo's AUTOLOAD will get called instead. Appropriate variables are filled in so that AUTOLOAD method can tell what sub it was called for. Only works for subs, not for global variables. (That's for perl 6, I expect) -- Dan --------------------------------------"it's like this"------------------- Dan Sugalski even samurai dan@sidhe.org have teddy bears and even teddy bears get drunk
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4