Пример #1
0
        private static Func<double, double[], double> GetOperation(string oper)
        {
            Operation op = new Operation(oper);

            switch (op.Value)
            {
                case Operation.ADD:  return  (l, r) =>  r.Aggregate(l,(a,b) => a + b);
                case Operation.MIN:  return  (l, r) =>  r.Aggregate(l,(a, b) => a - b);
                case Operation.MULT: return  (l, r) =>  r.Aggregate(l,(a, b) => a * b);
                case Operation.DIV:  return  (l, r) =>  {   op.FailIf(r.Last() == 0D, LispError.DIVIDE_BY_ZERO);
                                                            return r.Aggregate(l, (a, b) => a / b);
                                                        };
                case Operation.POW:  return  (l, r) =>  {
                                                            op.FailIf(r.Count() != 1, LispError.INVALID_ARGS_NUM);
                                                            return Math.Pow(l, r[0]);
                                                        };
                case Operation.AVG:  return  (l, r) =>  {
                                                            op.FailIf(r.Count() == 0, LispError.INVALID_ARGS_NUM);
                                                            return r.Aggregate(l, (a, b) => a + b) / (1 + r.Count());
                                                        };
            }
            return null;
        }