power_proc_generator returns a lambda that uses (and modifies) the value of a variable in the surrounding area. This is called a closure - the returned function "closes" above the value of the value variable. Therefore, every time you call the returned function, it is multiplied by value by two. The important part is that value stays between calls to power_proc.call , so you are power_proc.call existing variable.
In addition, to clarify the difference between printing power_proc_generator and power_proc.call - power_proc_generator , it calls a new function every time, so you never see the value increase. power_proc.call , on the other hand, continues to call the same function several times.
Peter source share