Programming Assignment 2: Lexical Scoping. R function is able to cache potentially time-consuming computations