summaryrefslogtreecommitdiff
path: root/test/factorial.lua
diff options
context:
space:
mode:
authorLua Team <team@lua.org>2010-05-18 12:00:00 +0000
committerrepogen <>2010-05-18 12:00:00 +0000
commitf970e1e83ed07bbcf8a20fc1a95f91a0a2aae620 (patch)
tree005b26e8ebf7553ba5c7a66700866be3e42443d0 /test/factorial.lua
parentecd48c2901f08a88db32139b97c35c59eba1f19e (diff)
downloadlua-github-5.2.0-work3.tar.gz
Lua 5.2.0-work35.2.0-work3
Diffstat (limited to 'test/factorial.lua')
-rw-r--r--test/factorial.lua32
1 files changed, 0 insertions, 32 deletions
diff --git a/test/factorial.lua b/test/factorial.lua
deleted file mode 100644
index 7c4cf0fa..00000000
--- a/test/factorial.lua
+++ /dev/null
@@ -1,32 +0,0 @@
--- 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