digitalmars.D - with statement
- tetsuya (49/49) Nov 18 2004 is there any reason why "with (Typename)" is not allowed?
is there any reason why "with (Typename)" is not allowed? like: class A { static int x, y; static int foo() { return x * y; } } void bar() { with (A) { .. . x .. y ..; foo(); .. } } to think of the use of 'with', i guess mixing namespace at class level or enum level is reasonable enough to be permitted. or furthermore, i'm doubting the need for the 'with' keyword. i'd rather propose smarter 'alias' for near semantics. it stands on "alias works for typenames and functions, why not for variables??" Specifically, it's gonna be more reasonable and flexible to write like: void bar() { alias A.x x; // alias for variables alias A.y y; alias A.foo foo; .. . x .. y ..; foo(); .. } or more compactly, void bar() { alias A; // alias with only one argument .. . x .. y ..; // compiler looks for the name table of class A foo(); .. } this would not only save the keyword 'with', but save the need for another block scope for it and could also be used within the class declaration to make the "implementation inheritance" easier to read and write. thanks for your consideration :)) tetsuya
Nov 18 2004