lua-users home
lua-l archive

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


> Why would it be desired to have a new anonymous function created for
> each call?
> 
> function a()
> 	return function () end
> end

Because the function statement creates closures. Try this:

 function add(x)
	 return function(y) return x+y end
 end

 add10=add(10)
 add20=add(20)
 print(add10(3),add20(3))

--lhf