| ▲ | wasmperson 3 hours ago | |
> 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: | ||
| ▲ | uecker 3 hours ago | parent [-] | |
I agree with your point. But I usually prefer the later anyway, because the code usually is not as nested anyway and having a name is often helpful, and also because I find the nested code with lambdas also not too readable. Other languages have better syntax for chaining functions in this way, i.e. with lambdas I would like to write like this:
(edit: or something, I think I got it a bit wrong, but you get the idea)But I agree, sometimes lambdas are better so it would be good to have both. (There is the classical hack to define lambdas using statement expressions and nested functions.) | ||