[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: evolutionary programming & Lua
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Thu, 19 Aug 1999 10:01:41 -0300 (EST)
Here is a simple implementation of arithmetic expressions in Lua that should
be adequate for evolutionary programming.
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
function E(x) print(eval(x)) end
E{add,1,{mul,2,3}}
E{sin,30}
--lhf