No, no actually. I only put a toy example. What I need to solve is related with storing data in the .tuc file when processes take a long time. Memoization doesn't work as data is lost with each new run.

Jairo

El mié, 24 de mar. de 2021 a la(s) 15:36, Aditya Mahajan (adityam@umich.edu) escribió:
On Wed, 24 Mar 2021, Jairo A. del Rio wrote:

> Hi, Hans. Here's my (miserably failing) attempt:
>
> \definedataset[nicedata]
>
> \starttext
>
> \startluacode
>
> local name = "nicedata"
>
>
> -- For exposition only
>
> local function dofactorial(n)
>
> local function inner(c,m)
>
> if m<2 then return c end
>
> return inner(c*m, m-1)
>
> end
>
> return inner(1,n)
>
> end

Is this an example or your actual use case? In case you want to just compute the factorial without doing tail recursion:

function factorial(n)
  local product = 1
  for i = 1,n do
    product = product * i
  end
  return product
end

is reasonable fast (for values of n for which factorial(n) doesn't overflow anyways).

Aditya