Feature request: one-statement functions without brackets

Downs default_357-line at yahoo.de
Mon Apr 2 03:47:23 PDT 2007


Downs wrote:
> Frits van Bommel wrote:
>> Downs wrote:
>>> Feature request: Allow functions of the form function-declaration 
>>> statement;
>>> Example: int test() return 5;
>>>
>>> This would make the function syntax closer to the way if/else, while, 
>>> for and similar
>>> statements' blocks are handled now, potentially making parsing 
>>> easier. It would
>>> also help with internal consistency.
>>> Also, it would allow methods like void test() synchronized(this) { }, 
>>> which to me just
>>> looks cleaner than using brackets to contain a single statement.
>>> I couldn't immediately imagine a case where this syntax might lead to 
>>> an ambiguity; if
>>> there is, I'm sorry.
>>>
>>>  -- awaiting feedback, downs
>>
>> Ambiguity:
>> ---
>> void foo()(T);
>> ---
>> No-implementation declaration of a no-template-argument template 
>> function that takes a T, or no-argument function that evaluates "T"?
>>
>> Of course, the practical use of a no-implementation template function 
>> declaration may be limited enough (is there any at all?) that banning 
>> it may not be much of a problem...
> Forgive my ignorance, but I don't get what you mean by "no-argument 
> function
> that evaluates T." Wouldn't that be foo()(T)? (without the void)
>  -- slightly confused, downs
Nevermind, got it. Sorry. Agreed.



More information about the Digitalmars-d mailing list