Exemplo n.º 1
0
        public IEnumerable <bool> retract(object Head, object Body)
        {
            Head = YP.getValue(Head);
            if (Head is Variable)
            {
                throw new PrologException("instantiation_error", "Head is an unbound variable");
            }
            object[] arguments = YP.getFunctorArgs(Head);

            // We always match Head from _allAnswers, and the Body is Atom.a("true").
            #pragma warning disable 0168, 0219
            foreach (bool l1 in YP.unify(Body, Atom.a("true")))
            {
                // The caller can assert another answer into this same predicate during yield, so we have to
                //   make a copy of the answers.
                foreach (object[] answer in _allAnswers.ToArray())
                {
                    foreach (bool l2 in YP.unifyArrays(arguments, answer))
                    {
                        _allAnswers.Remove(answer);
                        clearIndexes();
                        yield return(false);
                    }
                }
            }
            #pragma warning restore 0168, 0219
        }
Exemplo n.º 2
0
        public IEnumerable <bool> clause(object Head, object Body)
        {
            Head = YP.getValue(Head);
            if (Head is Variable)
            {
                throw new PrologException("instantiation_error", "Head is an unbound variable");
            }
            object[] arguments = YP.getFunctorArgs(Head);

            // We always match Head from _allAnswers, and the Body is Atom.TRUE.
            foreach (bool l1 in YP.unify(Body, Atom.TRUE))
            {
                // The caller can assert another answer into this same predicate during yield, so we have to
                //   make a copy of the answers.
                foreach (object[] answer in _allAnswers.ToArray())
                {
                    foreach (bool l2 in YP.unifyArrays(arguments, answer))
                    {
                        yield return(false);
                    }
                }
            }
        }