factorial.lua
来自「著名的LUA脚本语言的解释器源码,该源码为5.1.2版本,详情参看其中的src」· LUA 代码 · 共 33 行
LUA
33 行
-- 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 + =
减小字号Ctrl + -
显示快捷键?