60 ms·
Lambdas are (among other things) nested functions. The "tendency to confuse the two" is a feature, not a bug. Bob knows how to draw quadrilaterals. He uses thi
by nwallin 6y ago
Lambdas are (among other things) nested functions. The "tendency to confuse the two" is a feature, not a bug.
Bob knows how to draw quadrilaterals. He uses this skill to draw rhombuses, rectangles, and parallelograms. IMHO you're arguing that Bob doesn't know how to draw rhombuses because the method he uses to draw rhombuses is a method to draw parallelograms.
Am I misunderstanding you?
- ben509 6y agoI think there is a distinction. A nested procedure ("function" is a bit misleading in imperative languages) can close over variables in the outer scope, but has to have its own isolated control. A truly[2] anonymous procedure can also close over control flow: fun hasZeros(ints: List<Int>): Boolean { ints.forEach { if (it == 0) return true // returns from hasZeros } return false } That's an example from Kotlin's docs. [1] [1]: https://kotlinlang.org/docs/reference/inline-functions.html https://kotlinlang.org/docs/reference/inline-functions.html [2]: "truly" in the sense it's never assigned to a name, and is known to not escape its surrounding scope, which is necessary if the compiler is going to allow it to, e.g. do a non-local return.
- nwallin 6y agoI think I'm glad C++ doesn't have that feature. Can you provide a ... slightly more real world example of what non-local returns are for? As described it sounds equally capable of shooting both varmints and one's own feet.