|
|
|
|
|
by pjakma
4685 days ago
|
|
Yeah, it's language sugar to capture variables (including automatics) from an outer scope and make them available to an anonymous function. This may involve copying the variables to other storage (e.g. to heap) if the anonymous function will be run outside the context of its caller. Also, the language may, if it provides some sugar to allow the anonymous function to appear to return to the caller, e.g. through async/yield/co-routine type semantics, also transparently copy back the variables to the callers' locations. As per another commentator, 'lambdas', 'closures' and 'anonymous functions' are used equivalently by different people and/or fields. As a C programmer primarily, I was long confused why higher-level programmers went on about "closures". They're nothing special, we do this kind of stuff in C all the time. We have to do it by hand ourselves, the language doesn't give us shortcuts. It's not really mysterious and we don't have fancy names for it. Sometimes I wonder if the reason some higher-level programmers treat these things so reverentially is, perhaps, because there is an element of mysticism to it, borne of lack of understanding of what is happening "under the hood"? |
|