getrecursiondepth
Andrew Dalke
adalke at mindspring.com
Fri Oct 1 14:21:28 EDT 2004
Manlio Perillo wrote:
> This is only the function signature!
> The problem is that I can't do:
>
> def my_function(a, b, *args, **kwargs, __max_depth = 4): ...
>
> The only way is to do:
> def my_function(a, b, max_depth = 4, *args, **kwargs): ...
>
> But in this way max_depth is 'exposed' to public.
> In the first example it is private.
My point, mentioned several times now, is that there's
nothing preventing you from making *two* functions.
The private one doesn't need the *args, **kwargs parameter
definition, and the public one doesn't need the depth
limit.
def _my_function(a, b, args, kwargs, max_depth = 4):
# do your recursive work here
def my_function(a, b, *args, **kwargs):
# the public entry to your system
return _my_function(a, b, args, kwargs)
>>Let's suppose you're
>>doing Ackermann's function
> What's the purpose of such a function?
It's a standard recursive function used for
benchmarks. It's often used to test how
well a language supports recursion because it
very quickly hits stack limits instead of
numeric limits.
I used it to make my example concrete by
showing how to have a public API which is
different than the API used by the actual
recursive function. I also used it to show
how that sort of split makes it easier to
add parameter checking, if it's needed.
Andrew
dalke at dalkescientific.com
More information about the Python-list
mailing list