lua-users home
lua-l archive

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


Tim Hill <drtimhill@gmail.com> writes:
> 2. Wrap the function in a closure that contains a reference to
> itself and recurse using the closure. Something like this:
>
> 	local function f1(n)
> 		if n == 0 then return 1 end
> 		return n * f1(n-1)
> 	end
> 	fact = f1
>
> This works but it takes the performance hit of the closure just to
> get the recursion.

It doesn't seem like much of a "performance hit", as a closure is only
created once, when the function is defined.

I certainly wouldn't worry about it...

-miles

-- 
"Suppose we've chosen the wrong god. Every time we go to church we're
just making him madder and madder." -- Homer Simpson