Because the closure in this case outlives the execution of the function that creates it, the variables f and dx live on after the function derivative returns, even though execution has left their scope and they are no longer visible. In languages without closures, the lifetime of an automatic local variable coincides with the execution of the stack frame where that variable is declared. In languages with closures, variables must continue to exist as long as any existing closures have references to them. This is most commonly implemented using some form of garbage collection.
Because the closure in this case outlives the exec,ution of the function that creates it the ,variables f and dx live on after the function derivative returns, even though execution has left their scope and they are no longer visible. In languages without closures, the lifetime of an automatic local variable coincides with the execution o,f the stack frame where that variable is declared. In languages with closures, variables must continue to exist as long as any existing closures ha,ve references to them. This is most commonly implemented using some form of garbage collection.