Martin Probst's weblog

Java closure syntax with a dash of Smalltalk

Tuesday, December 18, 2007, 12:24 — 0 comments Edit

I just came across a curious paragraph in the Closure Syntax Proposal for Java 7 by Gilad Bracha, Neal Gafter, James Gosling, and Peter von der Ahé, on page 8:

We are also experimenting with generalizing this to support an invocation syntax that interleaves parts of the method name and its arguments, which would allow more general user-defined control structures that look like if, if-else, do-while, and so on.

This doesn't play well with the return statement being given a new meaning within a closure; it returns from the closure instead of the enclosing method/function. Perhaps the return from a closure should be given a different syntax:

^ expression;

Note the Smalltalk-ish “^” return symbol, with the reference to interleaving method name parts and arguments before. I first thought this was an insider joke, but they seem to be serious about that ;-)

Other than that the proposal is really nice, I think. It fits very well into the existing Java syntax - the new blocks are simply blocks as they always have been, and the syntax for nested functions looks exactly like regular Java methods. They also seem to have made up their minds about the necessary type system changes.


No comments.