Exemplo n.º 1
0
        public XClause Bind(XPredicate predicate)
        {
            if (predicate.Signature != Predicate.Signature)
            {
                return(null);
            }

            var copy = this.Clone();

            for (int i = 0; i < predicate.Signature.Arity; ++i)
            {
                var sArg = predicate.Vars[i];
                var dArg = copy.Predicate.Vars[i];

                if (sArg.Type == XType.Const && dArg.Type == XType.Const && sArg.Value != dArg.Value)
                {
                    return(null);
                }

                if (sArg != dArg)
                {
                    if (dArg.Type != XType.Const)
                    {
                        for (int j = 0; j < copy.Predicate.Signature.Arity; ++j)
                        {
                            if (copy.Predicate.Vars[j] == dArg)
                            {
                                copy.Predicate.Vars[j] = sArg;

                                if (copy.Body != null)
                                {
                                    copy.Body.Bind(dArg, sArg);
                                }
                            }
                        }
                    }
                    else if (sArg.Type != XType.Const)
                    {
                        predicate.Bind(sArg, dArg);
                    }
                }
            }

            return(copy);
        }