factorial.lua

来自「这是快速高效的脚本语言 LUA 的 win 移植到 ce 的版本. 这是 5.1」· 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 + -
显示快捷键?