Java Closures Tutorial
JSR Proposal: Closures for Java, section 2:
'This JSR provides support for operating on an arbitrary "block of Java code", or body, which is either a statement list, an expression, or a combination of both. We call the mechanism a closure expression. Wrapping statements or an expression in a closure expression does not change their meaning, but merely defers their execution. Evaluating a closure expression produces a closure object. The closure object can later be invoked, which results in execution of the body, yielding the value of the expression (if one was present) to the invoker. A closure expression can have parameters, which act as variables whose scope is the body. In this case the invoker of the closure object must provide compatible arguments, which become the values for the parameters.'
This tutorial does not describe the whole proposal but only the features implemented in the prototype compiler. All examples in this tutorial were tested against the early prototype available at http://www.javac.info. Current version: closures.tar.gz

5 comments:
How do I build and test against the closure prototype code?
As long as you have Java 6 in your path (you'll need to execute java and javac from the command line), then you can unzip the files and move to the bin folder within there, and then call java.bat and javac.bat to use the prototype.
It would be great if the .ztar file could contain an example, but I got it all working so it's not a big issue for me.
Java boys, time to learn Lisp!
As far as the Closure Syntax have you thought of alternatives to "=>" ?
I've always like how "::" looks if nothing else, and C++ confusions aside, if I saw "::" in a Java program I wonder what it was doing there. "=>" would surely be read as a boolean operation by the uninformed.
There are several alternatives to "=>". My personal preference is "->" but "::" is not bad too.
Post a Comment