[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: [ANN] Microlight (was Re: paving cowpaths with libraries)
- From: Miles Bader <miles@...>
- Date: Fri, 17 Feb 2012 16:21:37 +0900
steve donovan <firstname.lastname@example.org> writes:
> tbuff is a recursive local function, so the symbol must be declared
> before the definition. It helps to remember that 'local function f' is
> short for 'local f = function' - so any reference to f in that
> _anonymous_ function doesn't find the local because it's not defined
> local tbuff
> tbuff = function (t,buff,k)
> .-- refer to local tbuff!
Er ... what?
$ cat x.lua
local function f (n) if n == 0 then return 1 else return n * f(n - 1) end end
print (f (5))
$ lua x.lua
Although "local function X ... end" is basically syntax sugar for
"local X = function ... end", it isn't exactly equivalent, as this
example shows: The former syntax makes the definition visible to the
function body, whereas the latter syntax does not.
In New York, most people don't have cars, so if you want to kill a person, you
have to take the subway to their house. And sometimes on the way, the train
is delayed and you get impatient, so you have to kill someone on the subway.