why unrestricted closures are always void?

Vladimir Kirichenko vladimir.kirichenko at gmail.com
Sat Nov 15 17:21:45 PST 2008


Zdenek Tronicek wrote:
> Neal, he means control invocation syntax. For example:

Yeah. In ruby which have similar facility I can write something like:

def _for(x, &f) yield x end

and than invoke it:

res = _for(5) do |x| x*2 end

It will be good thing to have ability to write control abstractions 
those could return results, i.e.:

Iterable<Integer> squares = yield(int i : someIterable()) { i * i }

will construct generator - similar to one that exists in bunch of other 
languages.

And it's just looks very strange:

//compiles fine
public static int f(int i, {int ==> int} block) { return block.invoke(i); }

//does fine
System.out.println(f(3, {int i ==> i*i }));

but:

f(int i : 3) { return i * i; }

reports error:

cannot return a value from method whose result type is void
            f(int i : 3) { return i * i; }

It's not void neither in closure nor in method.

-- 
Best Regards,
Vladimir Kirichenko

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 254 bytes
Desc: OpenPGP digital signature
Url : http://mail.openjdk.java.net/pipermail/closures-dev/attachments/20081116/48892fb4/attachment.bin 


More information about the closures-dev mailing list