functions that use variables that are in scope but don’t get passed in as parameters
A function object combining both executable code and some variables from the surrounding lexical environment is called a lexical closure.
Different languages handle this kind of thing differently. Closures were motivated by lambda calculus, so they’re a common feature of languages with higher-order functions. (Although lambda calculus itself has no such concept, it emerges naturally as an optimization when trying to write an efficient evaluator for it.)
Python added these with PEP 227 when it gained lexical scoping, years before I started using the language.
A function object combining both executable code and some variables from the surrounding lexical environment is called a lexical closure.
Different languages handle this kind of thing differently. Closures were motivated by lambda calculus, so they’re a common feature of languages with higher-order functions. (Although lambda calculus itself has no such concept, it emerges naturally as an optimization when trying to write an efficient evaluator for it.)
Python added these with PEP 227 when it gained lexical scoping, years before I started using the language.