diff options
author | Lua Team <team@lua.org> | 2000-11-06 12:00:00 +0000 |
---|---|---|
committer | repogen <> | 2000-11-06 12:00:00 +0000 |
commit | 8cb71cb5548e3138e5d4e4744f52c79d9fafb116 (patch) | |
tree | 25859eb162c67eafc46866e0ec3a9a7ebf93157a /test/lisp.lua | |
parent | b7610da5fed99f59ac73ae452da8839a0f2c1bda (diff) | |
download | lua-github-4.0.tar.gz |
Lua 4.04.0
Diffstat (limited to 'test/lisp.lua')
-rw-r--r-- | test/lisp.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/test/lisp.lua b/test/lisp.lua new file mode 100644 index 00000000..e6bcd084 --- /dev/null +++ b/test/lisp.lua @@ -0,0 +1,22 @@ +-- a simple LISP evaluator + +function eval(x) + if type(x)=="table" then + return eval(x[1])(eval(x[2]),eval(x[3])) + else + return x + end +end + +function add(x,y) return x+y end +function sub(x,y) return x-y end +function mul(x,y) return x*y end +function div(x,y) return x/y end +function pow(x,y) return x^y end + +-- an example + +function E(x) print(eval(x)) end + +E{add,1,{mul,2,3}} +E{sin,60} |