コード例 #1
0
ファイル: Context.cs プロジェクト: polytronicgr/Axiverse
        public Symbol Evaluate(Symbol symbol)
        {
            if (symbol is Expression expression && expression.Count > 0)
            {
                Expression.Builder builder = new Expression.Builder(expression);
                for (int i = 0; i < builder.Count; i++)
                {
                    if (builder.Arguments[i] is Expression)
                    {
                        builder.Arguments[i] = Evaluate(builder[i]);
                    }
                }

                if (Evaluators.TryGetValue(builder[0], out var evaluator))
                {
                    symbol = evaluator.Evaluate(builder.Build(), this);
                }
            }

            History.Insert(0, symbol);

            for (int i = 0; i < Math.Min(History.Count, 10); i++)
            {
                Variable[Atom.OfHistory(i)] = History[i];
            }

            return(symbol);
        }