digitalmars.D - WithStatement
- Shahid (29/29) Jul 24 2011 I've been using the WithStatement alot recently and there's a situation
- bearophile (5/15) Jul 24 2011 If you extend this idea to if/while/for statements too, the end result i...
- KennyTM~ (11/26) Jul 24 2011 Not exactly. The ':' scope isn't terminated with de-dent, e.g. the
- KennyTM~ (18/47) Jul 24 2011 @property string usingNamespace(S)() {
I've been using the WithStatement alot recently and there's a situation that's really bugging me. my code is similar to the following: struct Struct { enum Enum1 { A, B, C } enum Enum2 { D, E, F } ... } T foo( ... ) { with ( Struct ) { bar( Enum1.A ); ... ... } } I'm wondering what others think about extending the WithStatement to take a colon, which would create an implicit scope similar to how Attributes work. eg: T func( ... ) { with ( Struct ): bar( Enum1.A ); ... ... }
Jul 24 2011
Shahid:I'm wondering what others think about extending the WithStatement to take a colon, which would create an implicit scope similar to how Attributes work. eg: T func( ... ) { with ( Struct ): bar( Enum1.A ); ...If you extend this idea to if/while/for statements too, the end result is a Python-D: http://delight.sourceforge.net/ Bye, bearophile
Jul 24 2011
On Jul 25, 11 03:51, bearophile wrote:Shahid:Not exactly. The ':' scope isn't terminated with de-dent, e.g. the language have to choose one of the two meanings in the following: foreach (i; a1): do_something_with(i); foreach (j; a2): do_something_with(j); (Actually this applies to this 'with' statement too. In with (A): with (B): should 'B' be nested in or replacing 'A'?)I'm wondering what others think about extending the WithStatement to take a colon, which would create an implicit scope similar to how Attributes work. eg: T func( ... ) { with ( Struct ): bar( Enum1.A ); ...If you extend this idea to if/while/for statements too, the end result is a Python-D: http://delight.sourceforge.net/ Bye, bearophile
Jul 24 2011
On Jul 25, 11 03:44, Shahid wrote:I've been using the WithStatement alot recently and there's a situation that's really bugging me. my code is similar to the following: struct Struct { enum Enum1 { A, B, C } enum Enum2 { D, E, F } ... } T foo( ... ) { with ( Struct ) { bar( Enum1.A ); ... ... } } I'm wondering what others think about extending the WithStatement to take a colon, which would create an implicit scope similar to how Attributes work. eg: T func( ... ) { with ( Struct ): bar( Enum1.A ); ... ... }property string usingNamespace(S)() { string res = ""; enum prefix = "alias " ~ S.stringof ~ '.'; foreach (m; __traits(allMembers, S)) { res ~= prefix ~ m ~ ' ' ~ m ~ ';'; } return res; } struct Struct { enum Enum1 { A, B, C } enum Enum2 { D, E, F } } void main() { mixin(usingNamespace!Struct); auto a = Enum1.A; auto b = Enum2.F; }
Jul 24 2011