title: What is the need or benefit to use an instance variable/function attribute to implement memoization vs passing down the memo in each call?
body: <p>In a lot of examples of memoization, I see it most commonly that people favor making a wrapper or decorator (or some language-dependent variation of this, such as using a higher-order function to close over a memo object) to store the results of previous function calls in an almost 'state-like' fashion.  Such an example can be seen below: </p>
  
  <pre><code>class Memoize(object):
      def __init__(self, func):
          self.func = func
          self.cache = {}
      def __call__(self, *args):
          if args in self.cache:
              return self.cache[args]
          ret = self.func(*args)
          self.cache[args] = ret
          return ret
  
  @Memoize
  def fib(n):
      if n &lt; 2:
          return 1
      return fib(n-2) + fib(n-1)
  </code></pre>
  
  <p>What is the difference / tradefoff between doing things this way, vs simply passing down a memo in the arguments of your function?  For example, like so:</p>
  
  <pre><code>def fib(n, memo = {}):
      if (n &lt; 2):
          return 1
      if (n in memo):
          return memo[n]
      memo[n] = fib(n - 1) + fib(n - 2)
      return memo[n]
  </code></pre>