/// <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));
        }
        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;
        }
        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;
        }
Exemple #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);
                }
            }
        }
Exemple #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);
                }
            }
        }
        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);
        }
        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);
        }
        /// <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);
        }
        /// <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;
        }