public object makeCopy(Variable.CopyStore copyStore)
 {
     object[] argsCopy = new object[_args.Length];
     for (int i = 0; i < _args.Length; ++i)
     {
         argsCopy[i] = YP.makeCopy(_args[i], copyStore);
     }
     return(new Functor(_name, argsCopy));
 }
예제 #2
0
 /// <summary>
 /// If bound, return YP.makeCopy for the value, else return copyStore.getCopy(this).
 /// However, if copyStore is null, just return this.
 /// </summary>
 /// <param name="copyStore"></param>
 /// <returns></returns>
 public object makeCopy(Variable.CopyStore copyStore)
 {
     if (_isBound)
     {
         return(YP.makeCopy(getValue(), copyStore));
     }
     else
     {
         return(copyStore == null ? this : copyStore.getCopy(this));
     }
 }
예제 #3
0
        /// <summary>
        /// Do the work of addAnswer or prependAnswer.
        /// </summary>
        /// <param name="answer"></param>
        private void addOrPrependAnswer(object[] answer, bool prepend)
        {
            if (answer.Length != _arity)
            {
                return;
            }

            // Store a copy of the answer array.
            object[]           answerCopy = new object[answer.Length];
            Variable.CopyStore copyStore  = new Variable.CopyStore();
            for (int i = 0; i < answer.Length; ++i)
            {
                answerCopy[i] = YP.makeCopy(answer[i], copyStore);
            }
            if (copyStore.getNUniqueVariables() > 0)
            {
                throw new InvalidOperationException
                          ("Elements of answer must be ground, but found " + copyStore.getNUniqueVariables() +
                          " unbound variables");
            }

            if (prepend)
            {
                _allAnswers.Insert(0, answerCopy);
                clearIndexes();
            }
            else
            {
                _allAnswers.Add(answerCopy);
                // If match has already indexed answers for a signature, we need to add
                //   this to the existing indexed answers.
                foreach (int signature in _gotAnswersForSignature.Keys)
                {
                    indexAnswerForSignature(answerCopy, signature);
                }
            }
        }
예제 #4
0
 public object makeCopy(Variable.CopyStore copyStore)
 {
     // Atom does not contain variables that need to be copied.
     return(this);
 }
        /// <summary>
        /// Do the work of addAnswer or prependAnswer.
        /// </summary>
        /// <param name="answer"></param>
        private void addOrPrependAnswer(object[] answer, bool prepend)
        {
            if (answer.Length != _arity)
                return;

            // Store a copy of the answer array.
            object[] answerCopy = new object[answer.Length];
            Variable.CopyStore copyStore = new Variable.CopyStore();
            for (int i = 0; i < answer.Length; ++i)
                answerCopy[i] = YP.makeCopy(answer[i], copyStore);
            if (copyStore.getNUniqueVariables() > 0)
                throw new InvalidOperationException
                    ("Elements of answer must be ground, but found " + copyStore.getNUniqueVariables() +
                     " unbound variables");

            if (prepend)
            {
                _allAnswers.Insert(0, answerCopy);
                clearIndexes();
            }
            else
            {
                _allAnswers.Add(answerCopy);
                // If match has already indexed answers for a signature, we need to add
                //   this to the existing indexed answers.
                foreach (int signature in _gotAnswersForSignature.Keys)
                    indexAnswerForSignature(answerCopy, signature);
            }
        }
 public object makeCopy(Variable.CopyStore copyStore)
 {
     return(new Functor1(_name, YP.makeCopy(_arg1, copyStore)));
 }