/// <summary>
        /// Unify Bag with the result. This frees the internal answers, so you can only call this once.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> result(object Bag)
        {
            object result = ListPair.make(_bagArray);

            // Try to free the memory.
            _bagArray = null;
            return(YP.unify(Bag, result));
        }
Пример #2
0
        public static object make(object[] array)
        {
            if (array.Length <= 0)
                return Atom.NIL;

            object result = Atom.NIL;
            // Start from the end.
            for (int i = array.Length - 1; i >= 0; --i)
                result = new ListPair(array[i], result);
            return result;
        }
Пример #3
0
        public static object make(List<object> list)
        {
            if (list.Count <= 0)
                return Atom.NIL;

            object result = Atom.NIL;
            // Start from the end.
            for (int i = list.Count - 1; i >= 0; --i)
                result = new ListPair(list[i], result);
            return result;
        }
Пример #4
0
        /// <summary>
        /// For each result, unify the _freeVariables and unify Bag with the associated bag.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> result(object Bag)
        {
            Variable bagArrayVariable = new Variable();

            foreach (bool l1 in resultArray(bagArrayVariable))
            {
                foreach (bool l2 in YP.unify(Bag, ListPair.make((List <object>)bagArrayVariable.getValue())))
                {
                    yield return(false);
                }
            }
        }
Пример #5
0
        /// <summary>
        /// For each result, unify the _freeVariables and unify Bag with the associated bag which is sorted
        /// with duplicates removed, as in setof.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> resultSet(object Bag)
        {
            Variable bagArrayVariable = new Variable();

            foreach (bool l1 in resultArray(bagArrayVariable))
            {
                List <object> bagArray = (List <object>)bagArrayVariable.getValue();
                YP.sortArray(bagArray);
                foreach (bool l2 in YP.unify(Bag, ListPair.makeWithoutRepeatedTerms(bagArray)))
                {
                    yield return(false);
                }
            }
        }
Пример #6
0
        public static object make(object[] array)
        {
            if (array.Length <= 0)
            {
                return(Atom.NIL);
            }

            object result = Atom.NIL;

            // Start from the end.
            for (int i = array.Length - 1; i >= 0; --i)
            {
                result = new ListPair(array[i], result);
            }
            return(result);
        }
Пример #7
0
        public static object make(List <object> list)
        {
            if (list.Count <= 0)
            {
                return(Atom.NIL);
            }

            object result = Atom.NIL;

            // Start from the end.
            for (int i = list.Count - 1; i >= 0; --i)
            {
                result = new ListPair(list[i], result);
            }
            return(result);
        }
Пример #8
0
        /// <summary>
        /// Return a ListPair version of array, where repeated elements
        /// (according to YP.termEqual) are removed.
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static object makeWithoutRepeatedTerms(object[] array)
        {
            if (array.Length <= 0)
            {
                return(Atom.NIL);
            }

            // Start from the end.
            object previousTerm = array[array.Length - 1];
            object result       = new ListPair(previousTerm, Atom.NIL);

            for (int i = array.Length - 2; i >= 0; --i)
            {
                object term = array[i];
                if (YP.termEqual(term, previousTerm))
                {
                    continue;
                }
                result       = new ListPair(term, result);
                previousTerm = term;
            }
            return(result);
        }
Пример #9
0
        /// <summary>
        /// Return a ListPair version of array, where repeated elements
        /// (according to YP.termEqual) are removed.
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static object makeWithoutRepeatedTerms(object[] array)
        {
            if (array.Length <= 0)
                return Atom.NIL;

            // Start from the end.
            object previousTerm = array[array.Length - 1];
            object result = new ListPair(previousTerm, Atom.NIL);
            for (int i = array.Length - 2; i >= 0; --i)
            {
                object term = array[i];
                if (YP.termEqual(term, previousTerm))
                    continue;
                result = new ListPair(term, result);
                previousTerm = term;
            }
            return result;
        }