Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
December 07, 2003 using namespace | ||||
---|---|---|---|---|
| ||||
Is there anything like using namespace in D. I've a load of variables in a private module, and I don't want to be aliasing them all. -Anderson |
December 07, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | Why doesn't "import myprivatemodule;" work for you? Sean "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bqvppk$17pp$1@digitaldaemon.com... > Is there anything like using namespace in D. I've a load of variables in a private module, and I don't want to be aliasing them all. > > -Anderson |
December 07, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | Sean L. Palmer wrote:
>Why doesn't "import myprivatemodule;" work for you?
>
>Sean
>
>"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message
>news:bqvppk$17pp$1@digitaldaemon.com...
>
>
>>Is there anything like using namespace in D. I've a load of variables in
>>a private module, and I don't want to be aliasing them all.
>>
>>-Anderson
>>
>>
>
>
>
>
I have to use private import, so I don't get conflicts with other modules. However I'm finding that I have to write std.blar.blar.blar everywhere, and it's really annoying.
-Anderson.
|
December 08, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | I see. Why can't you just put all your variables as privates in the main file? They're shared between more than one module? So you're saying that private import doesn't give you unqualified access to the symbols? That is a heavy price to pay to keep the symbols from being visible to the main module's user. You want some kind of bulk alias? import private mymodule; alias mymodule.* *; Sean "J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:br0c4l$21n5$2@digitaldaemon.com... > Sean L. Palmer wrote: > > >Why doesn't "import myprivatemodule;" work for you? > > > >Sean > > > >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bqvppk$17pp$1@digitaldaemon.com... > > > > > >>Is there anything like using namespace in D. I've a load of variables in a private module, and I don't want to be aliasing them all. > >> > >>-Anderson > >> > >> > > > > > > > > > I have to use private import, so I don't get conflicts with other modules. However I'm finding that I have to write std.blar.blar.blar everywhere, and it's really annoying. > > -Anderson. > |
December 08, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean L. Palmer | I think that he wants to say as following, maybe. For example, one defines class `CryptFile' in module `robert_20031021.fileutils.crypt_file' and another defines class having the same name `CryptFile' in module `anderson_library.fileutils.crypt_file'. Then, if one wants to use both of these two classes in the same file, he/she has to use `robert_20031021.fileutils.crypt_file.CryptFile' and `anderson_library.fileutils.crypt_file.CryptFile' (probably they are used after aliasing.) This problem occurs because the *unique* names appear *top* of the name chain. If these are `fileutils.crypt_file.robert_20031021.CryptFile' and `fileutils.crypt_file.anderson_library.CryptFile' (here, `robert_20031021' and `anderson_library' are namespaces), such a problem doesn't occur. Even if one wants to alias them, he/she can do it only `robert_20031021' and `anderson_library' are aliased, which are very short, can be reused, and enough if there are a few conflicting pairs. In article <br1h1d$qvq$1@digitaldaemon.com>, Sean L. Palmer says... > >I see. Why can't you just put all your variables as privates in the main file? They're shared between more than one module? > >So you're saying that private import doesn't give you unqualified access to the symbols? That is a heavy price to pay to keep the symbols from being visible to the main module's user. > >You want some kind of bulk alias? > >import private mymodule; >alias mymodule.* *; > >Sean > > >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:br0c4l$21n5$2@digitaldaemon.com... >> Sean L. Palmer wrote: >> >> >Why doesn't "import myprivatemodule;" work for you? >> > >> >Sean >> > >> >"J Anderson" <REMOVEanderson@badmama.com.au> wrote in message news:bqvppk$17pp$1@digitaldaemon.com... >> > >> > >> >>Is there anything like using namespace in D. I've a load of variables in a private module, and I don't want to be aliasing them all. >> >> >> >>-Anderson >> >> >> >> >> > >> > >> > >> > >> I have to use private import, so I don't get conflicts with other modules. However I'm finding that I have to write std.blar.blar.blar everywhere, and it's really annoying. >> >> -Anderson. >> > > Robert (Japanese) |
December 08, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | Robert wrote: >I think that he wants to say as following, maybe. > >For example, one defines class `CryptFile' in module >`robert_20031021.fileutils.crypt_file' and >another defines class having the same name `CryptFile' in module >`anderson_library.fileutils.crypt_file'. >Then, if one wants to use both of these two classes in the same file, >he/she has to use >`robert_20031021.fileutils.crypt_file.CryptFile' and `anderson_library.fileutils.crypt_file.CryptFile' >(probably they are used after aliasing.) > >This problem occurs because the *unique* names appear *top* of the name chain. >If these are `fileutils.crypt_file.robert_20031021.CryptFile' and >`fileutils.crypt_file.anderson_library.CryptFile' >(here, `robert_20031021' and `anderson_library' are namespaces), >such a problem doesn't occur. >Even if one wants to alias them, >he/she can do it only `robert_20031021' and `anderson_library' are aliased, >which are very short, can be reused, >and enough if there are a few conflicting pairs. > > > > I'm probably doing something wrong. In the dig ( http://jcc_7.tripod.com/d/dig.html) modifications (to get it to compile with 0.76) I kept getting std conflicts, so I used the full namespace. I think this may be the cause: ie (I think this is how it is on the basic level) --File 2 module x; private import std.c.windows.windows; private import y; -- File 2 module y; private import x; import std.c.windows.windows; //Causes conflict error //or private import std.c.windows.windows; //Causes conflict error //Which means that I have to either alias it with a different term. The problem with alias is that you have to think of a new term. alias std.c.windows.windows.BOOL BOOL; //Causes error (BOOL already exists, although I can't access it) alias std.c.windows.windows.BOOL _BOOL; //This is ok, but now I've changed the term name, and have to replace BOOL with _BOOL. Or I can write std.c.windows.windows.BOOL, everytime I want to use bool. For dig it was easier just to search replace BOOL with std.c.windows.windows.BOOL. Anyway, I'm probably missing something. -Anderson |
December 11, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to J Anderson | In article <br25qr$1q27$1@digitaldaemon.com>, J Anderson says... >I'm probably doing something wrong. In the dig ( http://jcc_7.tripod.com/d/dig.html) modifications (to get it to compile with 0.76) I kept getting std conflicts, so I used the full namespace. I think this may be the cause: > >ie (I think this is how it is on the basic level) >--File 2 >module x; >private import std.c.windows.windows; >private import y; > >-- File 2 >module y; >private import x; >import std.c.windows.windows; //Causes conflict error >//or >private import std.c.windows.windows; //Causes conflict error > >//Which means that I have to either alias it with a different term. The >problem with alias is that you have to think of a new term. >alias std.c.windows.windows.BOOL BOOL; //Causes error (BOOL already >exists, although I can't access it) >alias std.c.windows.windows.BOOL _BOOL; //This is ok, but now I've >changed the term name, and have to replace BOOL with _BOOL. > >Or I can write std.c.windows.windows.BOOL, everytime I want to use bool. For dig it was easier just to search replace BOOL with std.c.windows.windows.BOOL. > >Anyway, I'm probably missing something. > >-Anderson > Hm... I couldn't re-create the conflict error. ------------------------------------- // x.d module x; private import std.c.windows.windows; private import y; void foo(BOOL a) { printf("x: %d\n", a); } void bar(BOOL a) { y.foo(a); } // y.d module y; private import x; private import std.c.windows.windows; void foo(BOOL a) { printf("y: %d\n", a); } void bar(BOOL a) { x.foo(a); } // main.d private import x; private import y; private import std.c.windows.windows; int main() { BOOL a = TRUE; x.foo(a); y.foo(a); return 0; } dmd -c main.d dmd -c x.d dmd -c y.d dmd -ofa main.obj x.obj y.obj ------------------------------------- /a x: 1 y: 1 y: 1 x: 1 ------------------------------------- It works if private -> public. Hmm. I may be missing something... I think, at this moment, this aliasing will help you to keep your code not dirty. alias std.c.windows.windows win; Robert (Japanese) |
December 11, 2003 Re: using namespace | ||||
---|---|---|---|---|
| ||||
Posted in reply to Robert | Robert wrote:
>In article <br25qr$1q27$1@digitaldaemon.com>, J Anderson says...
>
>
>>I'm probably doing something wrong. In the dig ( http://jcc_7.tripod.com/d/dig.html) modifications (to get it to compile with 0.76) I kept getting std conflicts, so I used the full namespace. I think this may be the cause:
>>
>>ie (I think this is how it is on the basic level)
>>--File 2
>>module x;
>>private import std.c.windows.windows;
>>private import y;
>>
>>-- File 2
>>module y;
>>private import x;
>>import std.c.windows.windows; //Causes conflict error
>>//or
>>private import std.c.windows.windows; //Causes conflict error
>>
>>//Which means that I have to either alias it with a different term. The problem with alias is that you have to think of a new term.
>>alias std.c.windows.windows.BOOL BOOL; //Causes error (BOOL already exists, although I can't access it)
>>alias std.c.windows.windows.BOOL _BOOL; //This is ok, but now I've changed the term name, and have to replace BOOL with _BOOL.
>>
>>Or I can write std.c.windows.windows.BOOL, everytime I want to use bool. For dig it was easier just to search replace BOOL with std.c.windows.windows.BOOL.
>>
>>Anyway, I'm probably missing something.
>>
>>-Anderson
>>
>>
>>
>
>Hm... I couldn't re-create the conflict error.
>
>-------------------------------------
>// x.d
>module x;
>
>private import std.c.windows.windows;
>private import y;
>
>void foo(BOOL a) {
>printf("x: %d\n", a);
>}
>
>void bar(BOOL a) {
>y.foo(a);
>}
>
>// y.d
>module y;
>
>private import x;
>private import std.c.windows.windows;
>
>void foo(BOOL a) {
>printf("y: %d\n", a);
>}
>
>void bar(BOOL a) {
>x.foo(a);
>}
>
>// main.d
>private import x;
>private import y;
>private import std.c.windows.windows;
>
>int main() {
>BOOL a = TRUE;
>x.foo(a);
>y.foo(a);
>return 0;
>}
>
>dmd -c main.d
>dmd -c x.d
>dmd -c y.d
>dmd -ofa main.obj x.obj y.obj
>-------------------------------------
>/a
>x: 1
>y: 1
>y: 1
>x: 1
>-------------------------------------
>It works if private -> public.
>Hmm. I may be missing something...
>
>
>I think, at this moment,
>this aliasing will help you to keep your code not dirty.
>
>alias std.c.windows.windows win;
>
>Robert (Japanese)
>
>
Thanks.
|
Copyright © 1999-2021 by the D Language Foundation