If you have some kind of expression and you want to evaluate it for a large number of data lines, then you can only compile it into the lambdas tree only once and not calculate any switches at each iteration at all;
For example, with such ast: {* (a, {+ (b, c)})}
The compilation function (in a very crude pseudo-language) will look something like this:
func (e *evaluator) compile(brunch ast) { switch brunch.type { case binaryOperator: switch brunch.op { case *: return func() {compile(brunch.arg0) * compile(brunch.arg1)} case +: return func() {compile(brunch.arg0) + compile(brunch.arg1)} } case BasicLit: return func() {return brunch.arg0} case Ident: return func(){return e.GetIdent(brunch.arg0)} } }
Thus, as a result, compilation returns func, which should be called on every line of your data, and there will be no switches or other calculations at all. The question remains about operations with data of different types, that is, for your own research;) This is an interesting approach, in situations where there is no mechanism for switching to the table: :) but I'm sure func call is a more complicated operation, and then a jump.
Exel source share