title: making function lazy in Python
body: <p>I want to write a wrapper function for <code>eternity</code> that will make it behave as if it's being lazily evaluated. In other words, its functionality should be made identical to that of the function <code>lazyeternity</code> below. I have this function <code>packageN</code> that takes a function and packages it into a lambda--or at least I think it does. (Packaging <code>lazyeternity</code> inside a lambda delayed its evaluation in the call of <code>etest</code>.) How can I modify <code>packageN</code> so that <code>eternity = packageN(eternity)</code> can mirror the behavior of <code>lazyeternity</code>?</p>
  
  <pre><code>    def eternity():
          return eternity()
  
      # How can I create a wrapper function for eternity...
      # that will make it behave identical to this function?
      def lazyeternity():
          return lambda: lazyeternity()
  
      def packageN(f):
          return lambda *x: f(*x)
  
      def etest(x, y):
          return x
  
      eternity = packageN(eternity)
  
      # I want these both to return 4.
      # Currently only the first one returns 4,...
      # because the second one evaluates the eternity()...
      # parameter forever. I want to delay the evaluation...
      # of the parameter.
      print etest(4, lazyeternity())
      print etest(4, eternity())
  </code></pre>