lua-users home
lua-l archive

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


> 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))

It makes sense now.  I was thinking about how C# implements anonymous
methods.  In C#, anonymous methods are just syntactic sugar; the
compiler pulls the function out and calls it.

Thanks for all of the responses!