3 ms·
C# was the first mainstream language with a C-style syntax to have them - anonymous delegates in C# 2 (2005), then lambdas with type inference in C# 4 (2010).
by int_19h 7y ago
C# was the first mainstream language with a C-style syntax to have them - anonymous delegates in C# 2 (2005), then lambdas with type inference in C# 4 (2010).
Java got them in Java 7 in 2011, more or less at the same time as C++11 did.
In any case, Java and C# closures weren't particularly helpful to C++, because they have only shown that a garbage-collected language can have them - the main complexity around closures is wrt memory management and ownership. Hence why C++ closures are very different from either Java or C#.
I suspect that C++ got the now-deprecated exception specifiers - throw() on functions - from Java. But not entirely sure.
- gpderetta 7y agoGCC has had closures in C in the form of nested functions for as long as I can remember(but only as downward funargs).
- saagarjha 7y agoAnd the implementation was always an outright catastrophe…
- int_19h 7y agoI'm not sure these qualify as closures. But if they do, then they've been around in that exact form (named local functions with language semantics preventing them from outliving their environment) since Algol-60.
- gpderetta 7y agoI guess you are right, a true closure need to be able to outlive the scope of the variables it is closing over. Anyway, I wasn't making any claim that C got them first, far from it.
- fanf2 7y agoI checked my copy of the C++ Programming Language (2nd edition, 1991) which has throw() exception specifiers on functions. The Java project started in 1991.