Esempio n. 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);
 }
Esempio n. 2
0
        public override LispExpression Reduce(LispContext context)
        {
            decimal number;

            return(decimal.TryParse(_value, out number) ? this : context[_value]);
        }
Esempio n. 3
0
 public abstract LispExpression Reduce(LispContext context);
Esempio n. 4
0
 public override LispExpression Reduce(LispContext context)
 {
     return(this);
 }
Esempio n. 5
0
 public override LispExpression Reduce(LispContext context)
 {
     return(new LispList(Expressions));
 }
Esempio n. 6
0
 public override LispExpression Reduce(LispContext context)
 {
     throw new NotSupportedException();
 }
Esempio n. 7
0
 public virtual LispExpression Apply(IEnumerable <LispExpression> expressions, LispContext context)
 {
     return(_func(expressions));
 }
        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));
        }
Esempio n. 9
0
 public ChildContext(LispContext parentContext)
 {
     _parentContext = parentContext;
 }