blob: e6bcd084240301c703f5bc5c49de0524302f2120 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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}
|