I've written a tail call optimization lib for python3. https://titania.fs.uni-saarland.de/projects/libtco It works fine.
I use a custom return, which throws the next function arguments as an exception and a decorator, which handles the exception.
One strength of the functools.lru_cache lies in caching results of calls initiated by the function itself (i.e. recursive call results).
However because of the exception, the intermediate results from the tail recursion don't end up in the cache, if my tail call optimization is used together with lru_cache.
So I would like to be able to manually add argument-result pairs in the cache. A manual lookup is not needed for my purpose, but I propose that there should be methods to 1. add argument-result pairs to the cache 2. lookup if there is a result for given arguments 3. lookup the result for given arguments if it exists (exception thrown otherwise) 4. invalidate specific cache entries (at the moment you can only invalidate the cache as a whole through func.cache_clear())
What do you think?
Best Regards, Constantin