[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: "dynamic" closures
- From: Gé Weijers <ge@...>
- Date: Tue, 01 Dec 2009 21:17:57 -0800
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())