3 ms·
PHP implements closures as objects and I wrote a blogpost which shows the equivalence at http://drupal4hu.com/node/339.html http://drupal4hu.com/node/339.html
by chx 10y ago
PHP implements closures as objects and I wrote a blogpost which shows the equivalence at http://drupal4hu.com/node/339.html http://drupal4hu.com/node/339.html .
- Sharlin 10y agoC++ too - a lambda expression (with optional captures) is literally defined in terms of transforming the expression into an instance of a local unnamed class. And of course Java where the equivalence is supremely explicit - before Java 8 anonymous inner classes were the way to implement closures, and the Java 8 lambda expressions are merely syntactic sugar for creating an equivalent AIC instance.
- greydius 10y ago> Java 8 lambda expressions are merely syntactic sugar for creating an equivalent AIC instance I think that's a decent way to explain java's lambda expressions to developers without fp experience, but it's not technically correct. Lambda expressions are compiled into static methods in the class file. /pedantic
- cheez 10y agoHah, I never thought of it that way. In Lisp, you use lambdas to define classes. In C++, you use classes to define lambdas.
- pitay 10y agoAh this reminds me of all the different proposals for closure syntax in Java before it was implemented, the following links put compare some of the proposals: 1. http://www.artima.com/weblogs/viewpost.jsp?thread=180638 http://www.artima.com/weblogs/viewpost.jsp?thread=180638 (Inner Classes or Closures) 2. http://www.artima.com/weblogs/viewpost.jsp?thread=182412 http://www.artima.com/weblogs/viewpost.jsp?thread=182412 (Clear, Consistent, and Concise Syntax (C3S) for Java) 3. https://www.artima.com/weblogs/viewpost.jsp?thread=202004 https://www.artima.com/weblogs/viewpost.jsp?thread=202004 (Comparing Inner Class/Closure Proposals) PS. I remember the Artima articles because I liked them at the time.