Possible enhancement: Concise return statements

Jacob Carlborg doob at me.com
Mon Aug 15 11:12:59 PDT 2011


On 2011-08-15 17:04, Mafi wrote:
> Am 15.08.2011 16:01, schrieb Jacob Carlborg:
>> Yes, please. In fact I would like that the last expression in all
>> functions and delegates to be automatically returned.
>>
>> When we're talking about improving the delegate syntax I would like to
>> have these two syntaxes for delegates:
>>
>> foo(x => x * x)
>>
>> and
>>
>> foo(x) {
>> x * x
>> }
>>
>
> I personally don't like number one but that's subjective.
> The second has a serious problem: it makes the grammer context
> sensitive. You can't distinguish such a call from a local function
> definition.
> Therefore I suggest:
> foo(x) do (...){
> ...
> }

How is that? A function definition requires a type and a name, not just 
a name. BTW, it works find in Scala, but that might be because functions 
start with the "def" keyword.

> 'do' is already a keyword but only once ten years used for a do...while
> loop. If the functions are named correctly it reads perfectly:
> when!SomeEvent do (ev) {
> }
>
> where when is:
> void when(T : Event)(void delegate(T) reaction) {...}

I would rather not have the "do" keyword there.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list