why unrestricted closures are always void?

Zdenek Tronicek tronicek at fel.cvut.cz
Sat Nov 15 15:07:45 PST 2008


Neal, he means control invocation syntax. For example:

   public static int control(int x, { int ==> void } block) {
     block.invoke(x);
     return 42;
   }

   public static void main(String[] args) {
     // this is ok
     int answer = control(1, { int i ==> System.out.println(i); });
     // but this does not compile
     answer = control(int i : 2) {
       System.out.println(i);
     }
   }

Z.
-- 
Zdenek Tronicek
Department of Computer Science and Engineering
Prague                   tel: +420 2 2435 7410
http://cs.felk.cvut.cz/~tronicek


Quoting Neal Gafter <neal at gafter.com>:

> Unrestricted closures are not so constrained: they can have any return type.
>
> On Fri, Nov 14, 2008 at 6:25 PM, Vladimir Kirichenko <
> vladimir.kirichenko at gmail.com> wrote:
>
>> This makes impossible to implement functional-style control abstractions
>> like generators:
>>
>> Iterable<Integer> squares = yield(int i : someIterable()) { i * i }
>>
>> int[] sqa =  for collect(int i : array) { i * i }
>>
>> It looks very inconsistent to be able to use control abstraction with
>> "void" code and to be unable to use it with "code with result".  It places
>> major limitation to usage of control abstractions. Is this really necessary?
>>
>> --
>> Best Regards,
>> Vladimir Kirichenko
>>
>>
>





More information about the closures-dev mailing list