public LazyBinaryOp(OP _x, String _Op, OP _y) { x = _x; Op = _Op; y = _y; if (funcs == null) { funcs = new Dictionary <String, Func <OP, OP, Tuple <int, string> > >(); funcs.Add("{", (x, y) => { var count = x.eval(); var acc = 0; var msg = count.Item2 + "{"; for (int i = 0; i < count.Item1; i++) { var res = y.eval(); acc += res.Item1; if (i > 0) { msg += " + " + res.Item2; } else { msg += res.Item2; } } msg += "}"; return(Tuple.Create(acc, msg)); } ); } }
public override Tuple <int, string> eval() { return(funcs[Op](x.eval())); }