4 ms·
What would you propose as the syntax?
by anon946 10y ago
What would you propose as the syntax?
- user982 10y agoApple extended C with block closures years ago. int b = 0; ^(int a) { return a*b; } The declaration for lambda variables is almost identical to function pointers, just with a ^ instead of a *, so there's nothing to learn (or unlearn, like C++ forces you to). The ^ looks like a lambda, and historically the lambda of lambda calculus actually was a caret accent over the variable. The argument list can be elided.
- anon946 10y agoLooking here (https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/WorkingwithBlocks/WorkingwithBlocks.html https://developer.apple.com/library/ios/documentation/Cocoa/...) for the details, I think this is going to largely be a matter of opinion. I prefer the C++ syntax, especially when it comes to capture by reference, for which the Apple syntax seems to require the __block storage type modifier.
- CJefferson 10y agoAnd this is why C++ couldn't use this notation, as they didn't want to break compability with this extension of Apple's.
- fanf2 10y agoCaret as the embryonic form of lambda is apparently a myth propagated by Barendregt, and lambda is just a random Greek letter to go with alpha, beta, and eta. http://researchblogs.cs.bham.ac.uk/thelablunch/2016/05/why-is-lambda-calculus-named-after-that-specific-greek-letter-do-not-believe-the-rumours/ http://researchblogs.cs.bham.ac.uk/thelablunch/2016/05/why-i...
- optforfon 10y agoI honestly would have much preferred they had a keyword so that it kinda matched the rest of the language. It feels a bit tacked on and hard to parse. Something like: lambda(arguments):capture list {...} Just seems way more clear. Looks more like a function or a class (and a lambda is sort of an in-between kind of thing anyway)