Informal: Syntax from an outside position

Jakob Praher jp at hapra.at
Sat Nov 21 01:48:22 PST 2009


Hi all,

disclaimer: I did not provide complete EBNF, I just want to get this 
ideas out and hope for feedback.

For me the biggest motivations for designing syntacic changes is to make 
it _orthogonal_ to other java language constructs. Therefore IMHO one 
should differentiate between:
* function handles as first class type
* creating closures

For function handles I would just use all the argument types that make 
up the funciton interface:

void bar( int (String,byte[]) f ) {
     f("test", new byte[] {...})
}

IMHO I would not differntiate the type of a closure from the type of a 
function handle. I think in languages like C++, C the alternative syntax 
is mainly because of memory management issues? Is there any other 
reason. E.g. if some static method (e.g. function) does already 
implement some functionality I would not have to use some kind of 
closure construction facilty, just pass this static method?

For creating closures I would use the new keyword for introducing them with

 "new" "(" FormalParameters_opt ")" BlockStatement .
 "new" "(" FormalParameters_opt ")" Expression .

for example:

void foo() {
    int (String, byte[] f) closure = new (String name, byte[] data) {
         System.out.println(name);
         return date.length;
    }
}

when doing this with the lock example, it would look like:

withLock(lock, new() {
     System.out.println("Hello");
});


Thanks for your feedback
Jakob


More information about the closures-dev mailing list