mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-10-11 08:51:12 +00:00
initial commit. This is icculus version 5542b94cae02a6333845854bbbd1abe0a259f1a4
This commit is contained in:
commit
3096eaf5e2
2519 changed files with 816064 additions and 0 deletions
32
ExternalLibs/lua-5.1.4/test/factorial.lua
Normal file
32
ExternalLibs/lua-5.1.4/test/factorial.lua
Normal file
|
@ -0,0 +1,32 @@
|
|||
-- function closures are powerful
|
||||
|
||||
-- traditional fixed-point operator from functional programming
|
||||
Y = 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 recursion
|
||||
F = function (f)
|
||||
return function (n)
|
||||
if n == 0 then return 1
|
||||
else return n*f(n-1) end
|
||||
end
|
||||
end
|
||||
|
||||
factorial = Y(F) -- factorial is the fixed point of F
|
||||
|
||||
-- now test it
|
||||
function test(x)
|
||||
io.write(x,"! = ",factorial(x),"\n")
|
||||
end
|
||||
|
||||
for n=0,16 do
|
||||
test(n)
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue