lua-users home
lua-l archive

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


On Mon, Jul 12, 2010 at 1:39 PM, Geoff Leyland
<geoff_leyland@fastmail.fm> wrote:
> On 13/07/2010, at 6:35 AM, Peter Cawley wrote:
>
>> Wherever you see "function", a closure is created. Otherwise you
>> wouldn't be able to set the environment of the resulting function
>> without affecting other functions.
>
> Thanks Peter!  That makes sense (in hindsight...).  In that case, does
>
> function f()
>  return function() end
> end
>
> f(); f(); f(); f(); f()
>
> create more heap objects than
>
> local function g() end
> function f() return g end
>
> f(); f(); f(); f(); f()
>
> ?
>
> Geoff
>
>

let's try:

function f()
  return function () end
end


v1 = f()
v2 = f()

print (v1 == v2)
=> false


local function g() end
function f() return g end

v1 = f()
v2 = f()
print (v1 == v2)
=> true


-- 
Javier