"""
Preparing for but not actually using decorators, this file defines
a function that wraps another function in a third function.
"""

def logcall(f):
    """A function-wrapping function:
    logcall(f) returns a function just like f
    except it prints its arguments and return values"""
    def logcall_wrapper(*args, **kargs):
        print(f.__name__,'arguments',args, kargs,)
        retval = f(*args, **kargs)
        print(f.__name__,'returns',retval)
        return retval
    # rename the wrapper; only matters for a few debugging tools
    logcall_wrapper.__name__ = 'logcall('+f.__name__+')'
    return logcall_wrapper

# using a function wrapper
labs = logcall(abs)
print([labs(x) for x in range(-2,3)])
# can replace a function with the wrapped version
abs = logcall(abs)
print([abs(x) for x in range(-2,3)])
# can even replace the replaced function, though its not clear why we would
abs = logcall(abs)
abs = logcall(abs)
print(abs(-340))