lua-users home
lua-l archive

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


2014-04-21 23:33 GMT+02:00 Sean Conner <sean@conman.org>:
> It was thus said that the Great Coroutines once stated:
>>
>> I always remember that local function f() ... end is equivalent to
>> local f; f = function () ... end because when I have to write
>> recursive functions it errors when it tries to call the
>> not-yet-declared identifier from within itself.

s/errors/would otherwise error/

>   You should try using the Y combinator.
>
> function Y(f)
>   local function g(...) return f(g,...) end
>   return g
> end
>
> print(Y(function(rec, x)
>           if x < 2 then
>             return 1
>           else
>             return x * rec(x-1)
>           end
>         end)(5))
>
>   -spc (Unfortunately, do declare Y with your conding standard requres the
>         use of Y ... )

I don't understand the very last point made, even after correcting two typos.