[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Function Addresses?
- From: "Aaron Brown" <arundelo@...>
- Date: Tue, 13 Jun 2006 11:26:31 -0400
Mike King wrote:
Can someone tell me why the following code reports two
different function addresses?
return function () return b() end
Every time a function expression (an expression of the form
"function(...) ... end") is evaluated, a new function is
created, even if that function would behave identically to
some other function. (If you don't want this, arrange for
the function expression in question to only be evaluated
once, e.g., by moving it outside of the function it's in.)
In this case, a is called, it returns a function, that
function is called, it calls b, which calls a, which returns
a new function, which is then printed. Then a is called,
and it returns yet another function, which is printed.
A simpler demonstration of the point made in the first