title: how to generate function from a function
body: <p>Hi I am writing a lot of function with the following form:</p>
  <pre><code>def is_match_a(doc):
      pattern = # spaCy patterns
      matcher = Matcher(nlp.vocab)
      matcher.add(&quot;match_a&quot;, [pattern])
      matches = matcher(doc)
      if matches:
          return True
  </code></pre>
  <p>I want to write a function that generate these function from a given pattern and name. I am thinking something like:</p>
  <pre><code>def generate_matcher(pattern, name):
      func = some code
      return func
  </code></pre>
  <p>so that ultimately, I can do something the following</p>
  <pre><code>is_match_a = generate_matcher(pattern_a, name_a)
  is_match_b = generate_matcher(pattern_b, name_b)
  if is_match_a(doc):
      # do something
  elif is_match_b(doc):
      # do something else
  </code></pre>
  <p>I am new to python and I can not wrap my head around how to go about this. Is this where you use decorator?</p>