Exemplo n.º 1
0
 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));
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 4
0
 public object makeCopy(Variable.CopyStore copyStore)
 {
     return(new Functor2(_name, YP.makeCopy(_arg1, copyStore),
                         YP.makeCopy(_arg2, copyStore)));
 }
Exemplo n.º 5
0
 public object makeCopy(Variable.CopyStore copyStore)
 {
     // Atom does not contain variables that need to be copied.
     return(this);
 }
Exemplo n.º 6
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);
            }
        }