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

            return(decimal.TryParse(_value, out number) ? this : context[_value]);
        }
 public abstract LispExpression Reduce(LispContext context);
Beispiel #4
0
 public override LispExpression Reduce(LispContext context)
 {
     return(this);
 }
 public override LispExpression Reduce(LispContext context)
 {
     return(new LispList(Expressions));
 }
 public override LispExpression Reduce(LispContext context)
 {
     throw new NotSupportedException();
 }
 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));
        }
 public ChildContext(LispContext parentContext)
 {
     _parentContext = parentContext;
 }