[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Fragile Recursion?
- From: GrayFace <sergroj@...>
- Date: Wed, 11 Apr 2012 01:08:06 +0700
do...end has nothing to do with a closure. A closure is an 'instance' of function, thus it's created once in any of your examples. In the first case it doesn't contain any upvalues in Lua 5.1, while it does in 5.2. In short, the 2) is faster.
I'd do it this way:
local function fact(n)
if n == 0 then return 1 end
return n * fact(n-1)
end
_G.fact = fact
--
Best regards,
Sergey Rozhenko mailto:sergroj@mail.ru