Re: Possible enhancement: Concise return statements

2011-08-17 Thread pillsy
== Quote from Walter Bright (newshou...@digitalmars.com)'s article > On 8/15/2011 12:19 PM, Jacob Carlborg wrote: > > Can't we always automatically return the last expression, even if it ends > > with a > > semicolon? > It interferes with auto return typing (such as void returns). Ignoring unin

Re: Possible enhancement: Concise return statements

2011-08-16 Thread Jacob Carlborg
On 2011-08-15 22:06, Walter Bright wrote: On 8/15/2011 12:19 PM, Jacob Carlborg wrote: Can't we always automatically return the last expression, even if it ends with a semicolon? It interferes with auto return typing (such as void returns). Don't know if this apply in this case but couldn't

Re: Possible enhancement: Concise return statements

2011-08-16 Thread Jacob Carlborg
On 2011-08-15 22:57, Andrei Alexandrescu wrote: On 8/15/11 2:19 PM, Jacob Carlborg wrote: On 2011-08-15 21:00, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been prop

Re: Possible enhancement: Concise return statements

2011-08-16 Thread Jacob Carlborg
On 2011-08-15 22:06, Walter Bright wrote: On 8/15/2011 12:19 PM, Jacob Carlborg wrote: Can't we always automatically return the last expression, even if it ends with a semicolon? It interferes with auto return typing (such as void returns). You mean that instead of void it would return somet

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Walter Bright
On 8/15/2011 2:00 PM, Jonathan M Davis wrote: It would be a big problem with regard to functions in general IMHO, but how do struct destructors and overloading apply to lambdas? It at least _seems_ like it would be possible to make it so that single-statement lambdas which have no return or ; but

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Timon Gehr
On 08/15/2011 11:15 PM, Andrew Wiley wrote: On Mon, Aug 15, 2011 at 1:57 PM, Andrei Alexandrescu mailto:seewebsiteforem...@erdani.org>> wrote: On 8/15/11 2:19 PM, Jacob Carlborg wrote: On 2011-08-15 21:00, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote:

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Andrew Wiley
On Mon, Aug 15, 2011 at 1:57 PM, Andrei Alexandrescu < seewebsiteforem...@erdani.org> wrote: > On 8/15/11 2:19 PM, Jacob Carlborg wrote: > >> On 2011-08-15 21:00, Walter Bright wrote: >> >>> On 8/15/2011 3:54 AM, Timon Gehr wrote: >>> 'When the last ExpressionStatement in a function body is m

Re: Possible enhancement: Concise return statements

2011-08-15 Thread bearophile
Steven Schveighoffer: > What is going to happen if someone adds an extra ';' ? Compiler error > ("no return statement") A specific syntax, usable just for delegates that are not void seems to solve some problems: { a => a * foo(a) } // OK { a, b => a * b } // OK { int a, int b => a * b } //

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Jonathan M Davis
On Monday, August 15, 2011 13:31 Walter Bright wrote: > On 8/15/2011 1:13 PM, Steven Schveighoffer wrote: > > On Mon, 15 Aug 2011 16:05:31 -0400, Walter Bright > > > > > > wrote: > >> On 8/15/2011 12:17 PM, Steven Schveighoffer wrote: > >>> What is going to happen if someone adds an extra ';' ? C

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Andrei Alexandrescu
On 8/15/11 2:19 PM, Jacob Carlborg wrote: On 2011-08-15 21:00, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been proposed several times before, it was also proposed f

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Walter Bright
On 8/15/2011 1:13 PM, Steven Schveighoffer wrote: On Mon, 15 Aug 2011 16:05:31 -0400, Walter Bright wrote: On 8/15/2011 12:17 PM, Steven Schveighoffer wrote: What is going to happen if someone adds an extra ';' ? Compiler error ("no return statement") Such lambdas are often used with 'auto'

Re: Possible enhancement: Concise return statements

2011-08-15 Thread David Nadlinger
On 8/15/11 10:05 PM, Walter Bright wrote: On 8/15/2011 12:17 PM, Steven Schveighoffer wrote: What is going to happen if someone adds an extra ';' ? Compiler error ("no return statement") Such lambdas are often used with 'auto' returns, so you'd get no compiler error, but a subtle in the way yo

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Steven Schveighoffer
On Mon, 15 Aug 2011 16:05:31 -0400, Walter Bright wrote: On 8/15/2011 12:17 PM, Steven Schveighoffer wrote: What is going to happen if someone adds an extra ';' ? Compiler error ("no return statement") Such lambdas are often used with 'auto' returns, so you'd get no compiler error, but

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Walter Bright
On 8/15/2011 12:19 PM, Jacob Carlborg wrote: Can't we always automatically return the last expression, even if it ends with a semicolon? It interferes with auto return typing (such as void returns).

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Walter Bright
On 8/15/2011 12:17 PM, Steven Schveighoffer wrote: What is going to happen if someone adds an extra ';' ? Compiler error ("no return statement") Such lambdas are often used with 'auto' returns, so you'd get no compiler error, but a subtle in the way your program works.

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Jacob Carlborg
On 2011-08-15 21:17, Steven Schveighoffer wrote: On Mon, 15 Aug 2011 15:00:03 -0400, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been proposed several times before

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Steven Schveighoffer
On Mon, 15 Aug 2011 15:00:03 -0400, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been proposed several times before, it was also proposed for C++0x. The diffic

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Jacob Carlborg
On 2011-08-15 21:00, Walter Bright wrote: On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been proposed several times before, it was also proposed for C++0x. The difficulty is it makes having

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Andrej Mitrovic
On 8/15/11, Walter Bright wrote: > > for (int i = 0; i < 10; i++); >... do this ... > > which has cost at least one expert developer I know an entire afternoon > staring > at it convinced there was a compiler bug because his loop executed only > once. > > (And this is why D disallows t

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Walter Bright
On 8/15/2011 3:54 AM, Timon Gehr wrote: 'When the last ExpressionStatement in a function body is missing the ';', it is implicitly returned.' This has been proposed several times before, it was also proposed for C++0x. The difficulty is it makes having a ; or not substantially alter the semant

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Jacob Carlborg
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 fo

Re: Possible enhancement: Concise return statements

2011-08-15 Thread David Nadlinger
On 8/15/11 7:53 PM, bearophile wrote: Timon Gehr: map!((a){a*foo(a)})(arr); You have picked a suboptimal example, because D/Phobos already allows you write this (because the delegate uses only global names beside its arguments): map!q{ a * foo(a) }(arr); No! As long as foo() is not in the

Re: Possible enhancement: Concise return statements

2011-08-15 Thread bearophile
Timon Gehr: > 'When the last ExpressionStatement in a function body is missing the > ';', it is implicitly returned.' I remember others in past suggest the same idea. This is a good sign because it means it's a natural enough syntax for D programmers. > map!((a){a*foo(a)})(arr); You have pic

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Mafi
Am 15.08.2011 16:01, schrieb Jacob Carlborg: On 2011-08-15 12:54, Timon Gehr wrote: Currently, when using delegates in D, there is 'return' all over the place. Eg: map!((a){return a*foo(a);})(arr); Many delegates consist of only one return statement. Writing 'return' is rather inconvenient and

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Mehrdad
On 8/15/2011 3:54 AM, Timon Gehr wrote: Currently, when using delegates in D, there is 'return' all over the place. Eg: map!((a){return a*foo(a);})(arr); Many delegates consist of only one return statement. Writing 'return' is rather inconvenient and adds to the general noise This is precise

Re: Possible enhancement: Concise return statements

2011-08-15 Thread Jacob Carlborg
On 2011-08-15 12:54, Timon Gehr wrote: Currently, when using delegates in D, there is 'return' all over the place. Eg: map!((a){return a*foo(a);})(arr); Many delegates consist of only one return statement. Writing 'return' is rather inconvenient and adds to the general noise. Now, I would like

Re: Possible enhancement: Concise return statements

2011-08-15 Thread simendsjo
On 15.08.2011 12:54, Timon Gehr wrote: Currently, when using delegates in D, there is 'return' all over the place. Eg: map!((a){return a*foo(a);})(arr); Many delegates consist of only one return statement. Writing 'return' is rather inconvenient and adds to the general noise. Now, I would like

Possible enhancement: Concise return statements

2011-08-15 Thread Timon Gehr
Currently, when using delegates in D, there is 'return' all over the place. Eg: map!((a){return a*foo(a);})(arr); Many delegates consist of only one return statement. Writing 'return' is rather inconvenient and adds to the general noise. Now, I would like to propose to enhance the language in