lua-users home
lua-l archive

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


> On Tue, Mar 19, 2013 at 3:11 PM, Roberto Ierusalimschy
> <roberto@inf.puc-rio.br> wrote:
> > Lua 5.2.2  Copyright (C) 1994-2013 Lua.org, PUC-Rio
> >> a = {}; for i = 1, 2 do a[i] = function () end end
> >> = a[1] == a[2]
> > true
> 
> And the same for 5.2.1 ;)

But not for Lua 5.1:

Lua 5.1.4  Copyright (C) 1994-2008 Lua.org, PUC-Rio
> a = {}; for i = 1, 2 do a[i] = function () end end
> = a[1] == a[2]
false


> But what precisely is the difference between this and the naive test?

Here there is only one syntactic instance of "function () end".


> And does it mean less overhead in creating such identical closures?

Hopefully yes, because there is no "creation" of identical closures;
only one is created and then reused when possible.

-- Roberto