/// <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());
        }
Exemple #3
0
 public Functor2(string name, object arg1, object arg2)
     : this(Atom.a(name), arg1, arg2)
 {
 }
 public Functor1(string name, object arg1)
     : this(Atom.a(name), arg1)
 {
 }
Exemple #5
0
 public Functor3(string name, object arg1, object arg2, object arg3)
     : this(Atom.a(name), arg1, arg2, arg3)
 {
 }
 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));
 }