lua-users home
lua-l archive

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


I know this has been talked about before, and I read all the posts in the archive on this. There wasn't an "accepted" method for going about it, so I wondered if this implementation is optimal:

function execute(func, ...)
  return func(...);
end;

function test(s)
  return execute(function(f)
    local fact;
    fact = function(n, ret)
      ret = ret or 1;
      if n == 0 then return 1 * ret end;
      return fact(n - 1, n * ret);
    end;
    return fact(f);
  end, s);
end;

test(3) --> 6

Comments?

-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing to do and always a clever thing to say."

-Will Durant