예제 #1
0
 public override LispExpression Reduce(LispContext context)
 {
     if (Expressions.Length > 0)
     {
         /*
          * if (!(Expressions[0] is LispAtom))
          * {
          *      throw new InvalidOperationException();
          * }
          * var func = (LispFunction)context[Expressions[0].ToString()];
          */
         var func = (LispFunction)Expressions[0].Reduce(context);
         try
         {
             return(func.Apply(Expressions.Skip(1), context));
         }
         catch (FunctionArityException e)
         {
             throw new AggregateException(string.Format("[{0}] {1}", Position, e.Message), e);
         }
     }
     return(this);
 }
예제 #2
0
        public override LispExpression Reduce(LispContext context)
        {
            decimal number;

            return(decimal.TryParse(_value, out number) ? this : context[_value]);
        }
예제 #3
0
 public abstract LispExpression Reduce(LispContext context);
예제 #4
0
 public override LispExpression Reduce(LispContext context)
 {
     return(this);
 }
예제 #5
0
 public override LispExpression Reduce(LispContext context)
 {
     return(new LispList(Expressions));
 }
예제 #6
0
 public override LispExpression Reduce(LispContext context)
 {
     throw new NotSupportedException();
 }
예제 #7
0
 public virtual LispExpression Apply(IEnumerable <LispExpression> expressions, LispContext context)
 {
     return(_func(expressions));
 }
예제 #8
0
        public override LispExpression Apply(IEnumerable <LispExpression> expressions, LispContext context)
        {
            var e = expressions as LispExpression[] ?? expressions.ToArray();

            if (_arguments.Length != e.Length)
            {
                throw new InvalidOperationException();
            }
            var childContext = new ChildContext(context);

            for (int i = 0; i < _arguments.Length; i++)
            {
                childContext[_arguments[i]] = e[i].Reduce(context);
            }
            return(_body.Reduce(childContext));
        }
예제 #9
0
 public ChildContext(LispContext parentContext)
 {
     _parentContext = parentContext;
 }