Дмитрий Рыбас on Mon, 15 Jul 2019 09:24:46 +0200


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: Using local variable for memoizing in recursion


As it appered that I did not subscribe (sent request to the wrong address), I couldn't answer...

Well, going back to memoizing, Bill wrote:

You can use local():

p(n,k)=
{
  local(M=Map());
  memo_p(n,k);
}
Using local() is partial solution: one has to use the same (shared) name of variable in both calling and called functions. Is it possible to declare local variable in function a() and somehow pass it's name (or other reference) to function b() ? 
Or better, somehow put recursive function b() inside function a() that creates map, calls recursive function and the destroys everything except returned result?
Regards,
Dmitry.