| ▲ | uecker 4 hours ago | |||||||
Lambdas are just anonymous nested functions. But I like named nested functions more because they are more readable and would prefer them in most cases. Ideally you have both as most languages have. I always wondered why C++ only added lambdas, but observing WG21 for a while, I assume this is just a random walk in language design. (not that it is different in WG14) | ||||||||
| ▲ | wasmperson 3 hours ago | parent | next [-] | |||||||
> Lambdas are just anonymous nested functions. The important feature of lambdas is that they are expressions, not that they lack a name. The advantage of function expressions is you can write the body of the function exactly at the place where it is used. With GCC nested functions you either have to write the body of the function before its first use or else write the declaration of the function twice. This matters for long chains of continuation passing:
Compare to the following, where the control flow is all out of order: | ||||||||
| ||||||||
| ▲ | eru 3 hours ago | parent | prev [-] | |||||||
I can write numbers like three by just writing 3 in my code. When I want a named number I use a syntax like x = 3. Why should functions be any different? A language doesn't need different ways to name things for each type of thing. Integers, strings, functions etc: they can all use the same mechanism for naming. | ||||||||
| ||||||||