lua-users home
lua-l archive

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


Lua is not unique in its interpretation of closures, earlier languages such as Algol68 and Pascal used the same one, as does Google's experimental 'Go' language, and even Scheme.

In the (impure) functional language Objective Caml you can simulate this behavior using 'ref'.

Another fun example:

local function counter(v)
   return function ()
       v = v + 1
       return v
   end
end

local f = counter(0)

print(f())
print(f())
print(f())