public void add() { if (_freeVariables == null) { // The goal has bound the values in _template but we don't bother with _freeVariables. _findallBagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); } else { // The goal has bound the values in _template and _freeVariables. // Find the entry for this set of _freeVariables values. object[] freeVariableValues = new object[_freeVariables.Length]; for (int i = 0; i < _freeVariables.Length; ++i) { freeVariableValues[i] = YP.getValue(_freeVariables[i]); } List <object> bagArray; if (!_bagForFreeVariables.TryGetValue(freeVariableValues, out bagArray)) { bagArray = new List <object>(); _bagForFreeVariables[freeVariableValues] = bagArray; } // Now copy the template and add to the bag for the freeVariables values. bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); } }
/// <summary> /// Create a PrologException where the Term is error(ErrorTerm, Message). /// This uses YP.makeCopy to copy the ErrorTerm and Message so that they are valid after unbinding. /// </summary> /// <param name="ErrorTerm">the error term of the error</param> /// <param name="Messsage">the message term of the error. If this is a string, it is converted to an /// Atom so it can be used by Prolog code. /// Message, converted to a string, is use as the printable exception message. /// </param> public PrologException(object ErrorTerm, object Message) : base(YP.getValue(Message).ToString()) { if (Message is string) { Message = Atom.a((string)Message); } _term = YP.makeCopy(new Functor2(Atom.a("error"), ErrorTerm, Message), new Variable.CopyStore()); }
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)); }
/// <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)); } }
/// <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 void add() { _bagArray.Add(YP.makeCopy(_template, new Variable.CopyStore())); }
/// <summary> /// Create a PrologException with the given Term. The printable exception message is the full Term. /// </summary> /// <param name="Term">the term of the exception</param> public PrologException(object Term) : base(YP.getValue(Term).ToString()) { _term = YP.makeCopy(Term, new Variable.CopyStore()); }
public object makeCopy(Variable.CopyStore copyStore) { return(new Functor2(_name, YP.makeCopy(_arg1, copyStore), YP.makeCopy(_arg2, copyStore))); }