Exemplo n.º 1
0
        public ILispNode Clone()
        {
            var result = new LispList();

            ForEach(x => result.Add(x.Clone()));

            return(result);
        }
Exemplo n.º 2
0
        public LispList(LispList parent)
        {
            Parent = parent;

            if (Parent != null)
            {
                Parent.Add(this);
            }
        }
Exemplo n.º 3
0
        public LispAtom(LispList parent, string tokenValue, Token token)
        {
            Parent     = parent;
            TokenValue = tokenValue;
            Token      = token;

            SetValue(tokenValue as object);

            if (Parent != null)
            {
                Parent.Add(this);
            }
        }
Exemplo n.º 4
0
        public ILispNode Eval(CallStack callStack, params object [] args)
        {
            try
            {
                // ()
                if (Count == 0)
                {
                    return(_nil);
                }

                var functor = this[0].Eval(callStack, false);
                // ( =>nil )
                if (functor is LispNil)
                {
                    return(_nil);
                }
                // ( =>missing )
                if (functor is LispMissing)
                {
                    return(functor);
                }

                var arguments = new LispList();
                do
                {
                    if (IsImproperList)
                    {
                        arguments.Add(this[1] as LispAtom);
                        continue;
                    }

                    arguments = new LispList(null, this.Skip(1));
                }while (false);

                // ( =>(lambda) ) and ( =>'funcname' )
                return(Functor.Apply(functor, arguments, callStack, args));
            }
            catch (LispException)
            {
                throw;
            }
            catch (Exception ex)
            {
                throw new LispException(this, "Exception while applying functor to arguments", ex);
            }
        }