background preloader

Reference

Facebook Twitter

Documentation

Database. Batteries. Windows XP Commands. Bicycle Safety: How to Not Get Hit by Cars. Closure (computer science) Def start(x): def increment(y): return x+y return increment The closures returned by start can be assigned to variables like first_inc and second_inc.

Closure (computer science)

Invoking increment through the closures returns the results below: first_inc = start(0) second_inc = start(8) first_inc(3) # returns 3 second_inc(3) # returns 11 # The x value remains the same for new calls to the function: first_inc(1) # returns 1 second_inc(2) # returns 10 In ML, local variables are allocated on a linear stack[citation needed]. When a closure is created, it copies the values of those variables that are needed by the closure into the closure's data structure.