internal ILambdaValue Eval(ILambdaValue arg, Dictionary <string, ILambdaValue> env)
        {
            var ev1 = new Dictionary <string, ILambdaValue>(env);

            ev1.Add(argName, arg);
            return(body.Eval(env));
        }
        public ILambdaValue Eval(Dictionary <string, ILambdaValue> env)
        {
            var v1 = left.Eval(env);
            var v2 = right.Eval(env);

            if (v1 is NumberValue && v2 is NumberValue)
            {
                return(new NumberValue((v1 as NumberValue).GetNumValue() + (v2 as NumberValue).GetNumValue()));
            }
            else
            {
                throw new InvalidOperationException("Adding non-numbers");
            }
        }
        public ILambdaValue Eval(Dictionary <string, ILambdaValue> env)
        {
            var arg1 = arg.Eval(env);
            var c    = f.Eval(env) as ClosureValue;

            if (c != null)
            {
                return(c.Eval(arg1, env));
            }
            else
            {
                throw new InvalidOperationException("Apply a non-function");
            }
        }
        public ILambdaValue Eval(Dictionary <string, ILambdaValue> env)
        {
            var b = condition.Eval(env);

            if (b is NumberValue)
            {
                if ((b as NumberValue).GetNumValue() == 1)
                {
                    return(trueValue.Eval(env));
                }
                else
                {
                    return(falseValue.Eval(env));
                }
            }
            else
            {
                throw new InvalidOperationException("Condition is not number");
            }
        }
 public static ILambdaValue Interpret(ILambdaExpression e)
 {
     return(e.Eval(new Dictionary <string, ILambdaValue>()));
 }