public IEnumerable <bool> retract(object Head, object Body) { Head = YP.getValue(Head); if (Head is Variable) { throw new PrologException("instantiation_error", "Head is an unbound variable"); } object[] arguments = YP.getFunctorArgs(Head); // We always match Head from _allAnswers, and the Body is Atom.a("true"). #pragma warning disable 0168, 0219 foreach (bool l1 in YP.unify(Body, Atom.a("true"))) { // The caller can assert another answer into this same predicate during yield, so we have to // make a copy of the answers. foreach (object[] answer in _allAnswers.ToArray()) { foreach (bool l2 in YP.unifyArrays(arguments, answer)) { _allAnswers.Remove(answer); clearIndexes(); yield return(false); } } } #pragma warning restore 0168, 0219 }
public UndefinedPredicateException(object message, Atom predicateName, int arity) : base(new Functor2 (Atom.a("existence_error"), Atom.a("procedure"), new Functor2(Atom.a("/"), predicateName, arity)), message) { _predicateName = predicateName; _arity = arity; }
/// <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()); }
/// <summary> /// Return an array of the elements in list or null if it is not /// a proper list. If list is Atom.NIL, return an array of zero elements. /// If the list or one of the tails of the list is Variable, raise an instantiation_error. /// This does not call YP.getValue on each element. /// </summary> /// <param name="list"></param> /// <returns></returns> public static object[] toArray(object list) { list = YP.getValue(list); if (list.Equals(Atom.NIL)) { return(new object[0]); } List <object> result = new List <object>(); object element = list; while (true) { if (element == Atom.NIL) { break; } if (element is Variable) { throw new PrologException(Atom.a("instantiation_error"), "List tail is an unbound variable"); } if (!(element is Functor2 && ((Functor2)element)._name == Atom.DOT)) { // Not a proper list. return(null); } result.Add(((Functor2)element)._arg1); element = YP.getValue(((Functor2)element)._arg2); } if (result.Count <= 0) { return(null); } return(result.ToArray()); }
public Functor(string name, object[] args) : this(Atom.a(name), args) { }
/// <summary> /// Call the main make, first converting name to an Atom. /// </summary> /// <param name="name"></param> /// <param name="args"></param> /// <returns></returns> public static object make(string name, object[] args) { return(make(Atom.a(name), args)); }
public Functor1(string name, object arg1) : this(Atom.a(name), arg1) { }
public Functor3(string name, object arg1, object arg2, object arg3) : this(Atom.a(name), arg1, arg2, arg3) { }
public Functor2(string name, object arg1, object arg2) : this(Atom.a(name), arg1, arg2) { }