Self function

Terry Reedy tjreedy at udel.edu
Mon May 4 17:54:50 EDT 2009


bearophileHUGS at lycos.com wrote:

> Another possible syntax:
> 
> def fact(n):
>     return 1 if n <= 1 else n * return(n - 1)
> 
> But I guess most people don't see this problem as important&common
> enough to justify changing the language.

Actually, I would like a way to refer to the current function from 
inside a function.  but I would like support in the language, so that 
the compiler patched the code after the function object is created to 
directly refer to the function object (or can the code object call the 
code object?) without any name lookup at all. [An possible objection to 
doing this is that the code might no longer be valid if used to make 
another function object, but I think this is so rare at to hardly worry 
about.] Your initial post seemed to be about a hackish work around that 
looked to me to make as much trouble as it saves.  So I did not respond.




More information about the Python-list mailing list