digitalmars.D - Feature request - type inference for new
- Janice Caron (28/28) Jun 16 2008 I've been quiet for a while. (Actually, I've been offline for a
- Koroskin Denis (7/35) Jun 16 2008 Well, this one doesn't improve readability. I wouldn't use that,
- Steven Schveighoffer (14/42) Jun 16 2008 You mean like:
- Janice Caron (3/5) Jun 16 2008 That's clever. I didn't think of that.
- Jason House (6/44) Jun 16 2008 I'd prefer using the auto keyword as a replacement for the missing type....
- Nick Sabalausky (6/12) Jun 16 2008 I'd have to agree with this. "c = new typeof(c);" is an improvement ove...
- Yossarian (10/55) Jun 16 2008 I'm not sure, if this suggestion doesn't break the language context-less...
- BCS (6/23) Jun 17 2008 That's fine, the syntax doesn't catch everything.
- downs (4/23) Jun 17 2008 Example usage:
I've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } } The type of funky is in the declaration, so why repeat it? Another example... class AnotherClassWithAVeryLongName { int x,y; this(int x, int y) { this.x = x; this.y = y; } } void foo(int a, int b) { AnotherClassWithAVeryLongName c; if (a < b) c = new(a,b); else c = new(b,a); } Again, no need to repeat the type of c, because it's in the declaration (this time a local declaration). This will only work for assignments, because D doesn't overload on return type. But still - I'm all for anything that saves typing.
Jun 16 2008
On Mon, 16 Jun 2008 21:23:19 +0400, Janice Caron <caron800 googlemail.com> wrote:I've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } } The type of funky is in the declaration, so why repeat it? Another example... class AnotherClassWithAVeryLongName { int x,y; this(int x, int y) { this.x = x; this.y = y; } } void foo(int a, int b) { AnotherClassWithAVeryLongName c; if (a < b) c = new(a,b); else c = new(b,a); } Again, no need to repeat the type of c, because it's in the declaration (this time a local declaration). This will only work for assignments, because D doesn't overload on return type. But still - I'm all for anything that saves typing.Well, this one doesn't improve readability. I wouldn't use that, especially if there is a bulk of code between AnotherClassWithAVeryLongName c; and c = new(a,b);
Jun 16 2008
"Janice Caron" wroteI've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } } The type of funky is in the declaration, so why repeat it?You mean like: funky = new typeof(funky); ??? Besides that, I would really REALLY like to have: class X { auto n = new SomeOtherClass; } be equivalent to putting n = new SomeOtherClass in the front of all the constructors.Another example... class AnotherClassWithAVeryLongName { int x,y; this(int x, int y) { this.x = x; this.y = y; } } void foo(int a, int b) { AnotherClassWithAVeryLongName c; if (a < b) c = new(a,b); else c = new(b,a); } Again, no need to repeat the type of c, because it's in the declaration (this time a local declaration). This will only work for assignments, because D doesn't overload on return type. But still - I'm all for anything that saves typing.if (a < b) c = new typeof(c)(a, b); else c = new typeof(c)(b, a); -Steve
Jun 16 2008
On 16/06/2008, Steven Schveighoffer <schveiguy yahoo.com> wrote:if (a < b) c = new typeof(c)(a, b); else c = new typeof(c)(b, a);That's clever. I didn't think of that. OK - request withdrawn.
Jun 16 2008
I'd prefer using the auto keyword as a replacement for the missing type... ie. the following candidate syntaxes: funky = new auto; funky = new auto(); c = new auto(a,b); c = new auto(b,a); Janice Caron Wrote:I've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } } The type of funky is in the declaration, so why repeat it? Another example... class AnotherClassWithAVeryLongName { int x,y; this(int x, int y) { this.x = x; this.y = y; } } void foo(int a, int b) { AnotherClassWithAVeryLongName c; if (a < b) c = new(a,b); else c = new(b,a); } Again, no need to repeat the type of c, because it's in the declaration (this time a local declaration). This will only work for assignments, because D doesn't overload on return type. But still - I'm all for anything that saves typing.
Jun 16 2008
"Jason House" <jason.james.house gmail.com> wrote in message news:g36f76$m7u$1 digitalmars.com...I'd prefer using the auto keyword as a replacement for the missing type... ie. the following candidate syntaxes: funky = new auto; funky = new auto(); c = new auto(a,b); c = new auto(b,a);I'd have to agree with this. "c = new typeof(c);" is an improvement over repeating the entire type, but still isn't totally DRY. Before you posted I was kinda thinking something like "c = new typeof(_lvalue);", but "c = new auto();" is much cleaner.
Jun 16 2008
Dne Mon, 16 Jun 2008 21:33:58 +0200 Jason House <jason.james.house gmail.com> napsal/-a:I'd prefer using the auto keyword as a replacement for the missing type... ie. the following candidate syntaxes: funky = new auto; funky = new auto(); c = new auto(a,b); c = new auto(b,a);I'm not sure, if this suggestion doesn't break the language context-less grammar. imagine: auto c = new auto (); .. what now? This is nonsense, but gramatically correct.Janice Caron Wrote:-- Tato zpráva byla vytvořena převratným poštovním klientem Opery: http://www.opera.com/mail/I've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } } The type of funky is in the declaration, so why repeat it? Another example... class AnotherClassWithAVeryLongName { int x,y; this(int x, int y) { this.x = x; this.y = y; } } void foo(int a, int b) { AnotherClassWithAVeryLongName c; if (a < b) c = new(a,b); else c = new(b,a); } Again, no need to repeat the type of c, because it's in the declaration (this time a local declaration). This will only work for assignments, because D doesn't overload on return type. But still - I'm all for anything that saves typing.
Jun 16 2008
Reply to Yossarian,Dne Mon, 16 Jun 2008 21:33:58 +0200 Jason House <jason.james.house gmail.com> napsal/-a:That's fine, the syntax doesn't catch everything. this is valid syntax right now but doesn't pass the semantic checks: int a = 1; char[] b = "abc" auto c = a ~ b;I'd prefer using the auto keyword as a replacement for the missing type... ie. the following candidate syntaxes: funky = new auto; funky = new auto(); c = new auto(a,b); c = new auto(b,a);I'm not sure, if this suggestion doesn't break the language context-less grammar. imagine: auto c = new auto (); .. what now? This is nonsense, but gramatically correct.
Jun 17 2008
Janice Caron wrote:I've been quiet for a while. (Actually, I've been offline for a while). So, I thought I'd better come back with a new feature request! :-) Type inference for new. Here's an example: class C(T) { Some!(Funky!(Class!(T))) funky; this() { funky = new; } }I quote from tools.base:void New(S, T...)(ref S inst, T t) { inst=new S(t); }Example usage:this() { New(funky); }--downs
Jun 17 2008