📄 factorial.lua
字号:
-- function closures are powerful-- traditional fixed-point operator from functional programmingY = function (g) local a = function (f) return f(f) end return a(function (f) return g(function (x) local c=f(f) return c(x) end) end)end-- factorial without recursionF = function (f) return function (n) if n == 0 then return 1 else return n*f(n-1) end end endfactorial = Y(F) -- factorial is the fixed point of F-- now test itfunction test(x) io.write(x,"! = ",factorial(x),"\n")endfor n=0,16 do test(n)end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -