示例#1
0
            public BaseTerm Eval() // evaluate the term
            {
                BaseTerm t = ChainEnd();

                if (!t.IsEvaluatable)
                {
                    IO.Error("{0} cannot be evaluated by is/2", t);
                }

                if (t is ValueTerm)
                {
                    return(t);                                    // a ValueTerm stands for itself
                }
                if (t.IsProperList && !((ListTerm)t).IsEvaluated) // evaluate all members recursively
                {
                    ListTerm        result = ListTerm.EMPTYLIST;
                    List <BaseTerm> tl     = ((ListTerm)t).ToList();

                    for (int i = tl.Count - 1; i >= 0; i--)
                    {
                        result = new ListTerm(tl [i].Eval(), result);
                    }

                    result.IsEvaluated = true;

                    return(result);
                }

                return(t.Apply());
            }