On Sat, Dec 5, 2015 at 6:11 PM Serhiy Storchaka <storchaka@gmail.com> wrote:

On 04.12.15 23:44, Bill Winslow wrote:

> def deterministic_recursive_calculation(input, partial_state=None):

> condition = do_some_calculations(input)

> if condition:

> return deterministic_recursive_calculation(reduced_input,

> some_state)

>

> I want to memoize this function for obvious reasons, but I need the

> lru_cache to ignore the partial_state argument, for its value does not

> affect the output, only the computation expense.

Memoize a closure.

def deterministic_calculation(input):

some_state = ...

@lru_cache()

def recursive_calculation(input):

nonlocal some_state

...

return recursive_calculation(reduced_input)

return recursive_calculation(input)

This would provide the dynamic programming aspect for the recursion, but not cache across successive calls to the outer function. It does look cleaner than the OO version.