Exemple #1
0
        public override LispNode Operate(LispEnvironment env, LispNode node)
        {
            if (node.Nested.Count != 1)
            {
                return(new LispTooManyArgsException(Contents, 1, node.Nested.Count));
            }

            var dnode = node.Take(0) as LispDataList;

            if (dnode == null)
            {
                return(new LispIncorrectArgTypesException(Contents, 0, LispNodeType.DATALIST.ToString(), node.NodeType.ToString()));
            }


            var x = new LispList {
                Nested = dnode.GetNodeCopy().Nested
            };

            return(Interpreter.Evaluate(env, x));
        }
Exemple #2
0
        private static LispNode EvaluateExpr(LispEnvironment env, LispNode node)
        {
            node.Nested = node
                          .Nested
                          .ConvertAll(item => Evaluate(env, item));

            if (node.Nested.Any(item => item is LispError))
            {
                var item = node.Nested.First(err => err is LispError);
                node.Nested.Clear();
                return(item);
            }

            // Empty Expression
            if (node.Nested.Count == 0)
            {
                return(node);
            }

            // Single value expression
            if (node.Nested.Count == 1)
            {
                return(node.Take(0));
            }


            var op = node.Pop() as LispFunction;

            if (op == null)
            {
                node.Nested.Clear();
                return(new LispNotSymbolException());
            }

            return(op.CallFunction(env, node));
        }