def memoize_nullary(f):
    """
    Memoizes a function that takes no arguments.  The memoization lasts only as
    long as we hold a reference to the returned function.
    """
    def func():
        if not hasattr(func, 'retval'):
            func.retval = f()
        return func.retval
    return func
def memoize_nullary ( f ) : def func ( ) : if not hasattr ( func , 'retval' ) : func . retval = f ( ) return func . retval return func
Memoizes a function that takes no arguments.  The memoization lasts only as
    long as we hold a reference to the returned function.