Pass same parameter in Recursive function

Diez B. Roggisch deets at nospam.web.de
Wed Sep 3 02:59:31 EDT 2008


Davy schrieb:
> On Sep 3, 11:57 am, "Chris Rebert" <c... at rebertia.com> wrote:
>> Assuming the function is tail-recursive or the "unchanging" arguments
>> are immutable, just use a closure:
> [SNIP]
> Hi Chris,
> 
> Thank you :)
> Perhaps I should clarify the problem.
> 1. the function is NOT tail-recursive
> 2. Yes, the arguments are immutable after I call the function the
> first time.
> 
> I think the best description of the problem may be:
> How to keep some argument constant and accessable in one function
> (especially, recursive function). We know that we can use something
> like self.parameter to keep the parameter constant and accessable in
> one class.


The same way chris showed you - using a closure, you can capture 
variables outside, and only pass the changing params.

The tail-recursion property isn't needed for that.

Diez



More information about the Python-list mailing list