blocks with attributes vs inlined lambda

Idan Arye GenericNPC at gmail.com
Sat Jun 8 10:06:01 PDT 2013


On Saturday, 8 June 2013 at 16:21:26 UTC, deadalnix wrote:
> On Saturday, 8 June 2013 at 16:13:28 UTC, monarch_dodra wrote:
>> On Saturday, 8 June 2013 at 15:56:47 UTC, deadalnix wrote:
>>>
>>> Sound like a nice idiom. Why is the first set of () needed ? 
>>> Can we change the grammar to remove them ?
>>
>> It's because you are actually declaring a lambda that takes no 
>> arguments, and has no name, and contains a body. BTW, you 
>> quoted my incomplete code, the correct code I wanted to post 
>> was:
>>
>> () nothrow {//anonymous lambade declaration
>>    //Body of the lambde
>> }() //actual call to lambda
>>
>> I'd want to be able to do this, without either the first or 
>> last set of (). The required change of grammar would mean 
>> there'd be no lambda at all afterwards.
>
> {} is a lambda already. The first set of () is optional.

Actually, the first set of `()` is required because of the 
`nothrow`. You can't write:

     nothrow {
         //body
     }();

because the `nothrow` in lambdas needs to be placed after the 
argument list - so you need an argument list.


More information about the Digitalmars-d mailing list