4 ms·
I don’t know any other language with lambdas which requires me to spell out explicitly which variables it should close over... so you tell me how Java, Scala, C
by doteka 6y ago
I don’t know any other language with lambdas which requires me to spell out explicitly which variables it should close over... so you tell me how Java, Scala, Clojure, Kotlin, Python, JavaScript, Rust, Go, C# and tens of others managed this clearly impossible feat of engineering.
- gpderetta 6y agoForced heap allocation and GC of course that would be unacceptable in C++. IIRC Rust uses capture modifiers similar to C++.
- steveklabnik 6y agoRust is not really the same as C++ here, you get "the compiler infers how to capture things" as the default behavior, and "take everything by value", which happens with the "move" keyword. We've found that these two cases cover the vast, vast, vast majority of usage, and so C++-style specific capture modifiers aren't necessary. You can emulate C++ style stuff by taking references outside of the closure and using move to capture only the reference.
- DCoder 6y ago> I don’t know any other language with lambdas which requires me to spell out explicitly which variables it should close over PHP closures have to specify which variables they close over, and whether it's done by-val or by-ref [0]. Nowadays there's also a shorthand single-expression-closure syntax that closes implicitly and by value [1]. [0]: https://www.php.net/manual/en/functions.anonymous.php#example-167 https://www.php.net/manual/en/functions.anonymous.php#exampl... [1]: https://www.php.net/manual/en/functions.arrow.php https://www.php.net/manual/en/functions.arrow.php