Exemplo n.º 1
0
        private bool IsPredicate(PrologObject fact, StringObject atom)
        {
            if (fact.Equals(atom))
            {
                return(true);
            }

            if (!(fact is StructureObject))
            {
                return(false);
            }

            StructureObject st = ((StructureObject)(fact));

            if (st.Functor.Equals(atom))
            {
                return(true);
            }

            if (!(st.Functor == IfPrimitive.GetInstance()))
            {
                return(false);
            }

            fact = st.Parameters[0];

            if (fact.Equals(atom))
            {
                return(true);
            }

            if (!(fact is StructureObject))
            {
                return(false);
            }

            st = (StructureObject)fact;

            if (st.Functor.Equals(atom))
            {
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
 public bool Unify(PrologObject po1, PrologObject po2)
 {
     po1 = po1.Dereference();
     po2 = po2.Dereference();
     if (po1.Equals(po2))
     {
         return(true);
     }
     if (po1 is Variable)
     {
         ((Variable)(po1)).Bind(po2);
         return(true);
     }
     if (po2 is Variable)
     {
         ((Variable)(po2)).Bind(po1);
         return(true);
     }
     if (po1 is StructureObject && po2 is StructureObject)
     {
         StructureObject st1 = ((StructureObject)(po1));
         StructureObject st2 = ((StructureObject)(po2));
         if (!(Unify(st1.Functor, st2.Functor)))
         {
             return(false);
         }
         if (!(st1.Arity == st2.Arity))
         {
             return(false);
         }
         for (int k = 0; k <= st1.Arity - 1; k++)
         {
             if (!(Unify(st1.Parameters[k], st2.Parameters[k])))
             {
                 return(false);
             }
         }
         return(true);
     }
     return(false);
 }