code: def match(subject: Expression, pattern: Pattern) -> Iterator[Substitution]:
      r
      if not is_constant(subject):
          raise ValueError("The subject for matching must be constant.")
      global_constraints = [c for c in pattern.constraints if not c.variables]
      local_constraints = set(c for c in pattern.constraints if c.variables)
      for subst in _match([subject], pattern.expression, Substitution(), local_constraints):
          for constraint in global_constraints:
              if not constraint(subst):
                  break
          else:
              yield subst
docs: r"""Tries to match the given *pattern* to the given *subject*.
  
      Yields each match in form of a substitution.
  
      Parameters:
          subject:
              An subject to match.
          pattern:
              The pattern to match.
  
      Yields:
          All possible match substitutions.
  
      Raises:
          ValueError:
              If the subject is not constant.