lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> So make a function that turns:
> 
>  {add,7,{mul,4,3}}
> 
> into:
> 
>  myFunc = dostring("return function () return args.1 + ( args.2 * args.3 )")
> 
> and precompile it. Then execute it with the current args:
> 
>  result = myFunc({7,4,3})
> 
> This is important for genetic algorithms because we typically run the
> same genome's algorithm over large data sets. (In my application I'm
> running each genome on about quater of a million data points to evaluate 
> it's fitness - this has to be done for 100s of genomes for 100s of generations) 
	Why don't you use a function like:

function E (t)
   if type(t) == "table"then
      return function () return args[1](E(args[2]), E(args[3])) end
   else
      return t
   end
end

	and write the expressions like:

E{add, 7, {mul, 4, 3}}

	I didn't tested it, but it's just for the idea.  I think
lhf has answered with a solution similar to that, but without the
function construction, isn't it?

	Tomas