public override bool Unify (BaseTerm t, VarStack varStack)
      {
        if ((t = t.ChainEnd ()) is Variable) // t not unified
        {
          ((Variable)t).Bind (this);
          varStack.Push (t);

          return true;
        }

        if (t is ListPatternTerm && arity == t.Arity) // two ListPatternTerms match if their rangeTerms match
        {
          for (int i = 0; i < arity; i++)
            if (!args [i].Unify (t.Args [i], varStack)) return false;

          return true;
        }

        if (t is ListTerm)
        {
          pattern = args; // pattern is searched ...
          target = ((ListTerm)t).ToList ();  // ... in target
          int ip = 0;
          int it = 0;

          return UnifyTailEx (ip, it, varStack);
        }

        return false;
      }
Exemplo n.º 2
0
    public bool Unify(Term t, VarStack varStack, bool occurCheck)
    {
      if (isUnified) return ULink.Unify(t, varStack, occurCheck);
      if (t.isUnified) return Unify(t.ULink, varStack, occurCheck);
      //Interpreter.UCount++;

      if (hasValue)
      {
        if (t.hasValue)
        {
          if (_functor.Equals(t._functor) && arity == t.Arity) // => two cuts will unify as well
          {
            for (int i = 0; i < arity; i++) if (!args[i].Unify(t.Arg(i), varStack, occurCheck)) return false;

            return true;
          }
          else
            return false;
        }
        // t is an unbound variable (add occur check here if deemed necessary)
        t.Bind(this);
        varStack.Push(t);
      }
      else // 'this' is an unbound variable. Add occur check here if deemed necessary
      {
        this.Bind(t);
        varStack.Push(this);
      }

      return true;
    }