I've been bitten by this too, and I also used parameterized factory functions. In general, I try to avoid using local variables declared outside the anon methods, and only deal with arguments, but of course, that is almost impossible to completely avoid.
Lars Fosdal Without capture, there's pretty much no point to anonymous methods. If you don't have capture, then what do anonymous methods add over the pre-existing procedural types?
Would be nice if we could choose to capture value or variable, as can be done in C++
ReplyDeleteDavid Heffernan Indeed.
ReplyDeleteDavid Heffernan Yes, that would be nice, but I think there is no hope......
ReplyDeleteNice example!
ReplyDeleteI've been bitten by this too, and I also used parameterized factory functions. In general, I try to avoid using local variables declared outside the anon methods, and only deal with arguments, but of course, that is almost impossible to completely avoid.
ReplyDeleteLars Fosdal Without capture, there's pretty much no point to anonymous methods. If you don't have capture, then what do anonymous methods add over the pre-existing procedural types?
ReplyDeleteVery nice example. Thank you!
ReplyDeleteDavid Heffernan I f.x. use them to inject comparators, conditional formatters, decorators, stylers and event handlers.
ReplyDeleteLars Fosdal But we could do all of that perfectly well without anonymous methods using other procedural types.
ReplyDeleteI guess the point you are making is that you can define them inline as opposed to having to declare a function elsewhere, give it a name, and so on.
David Heffernan True that. Inline declaration is convenient - and it can be combined with assignment of regular declared methods.
ReplyDeleteAnd imagine how much nicer it would be if we had lambda syntax
ReplyDeleteDavid Heffernan That would indeed be nice in some settings.
ReplyDelete