[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- 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 <steve.j.donovan@gmail.com> 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
> yet.
>
> local tbuff
> tbuff = function (t,buff,k)
> .-- refer to local tbuff!
> ...
> end
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
120
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.
-miles
--
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.
[George Carlin]