digitalmars.D - Public Imports?
- Trevor Parscal (42/42) Jun 02 2005 Why is it that if I have a module that I am using to import other
- Phoenix (10/60) Jun 02 2005 i think, that the code should be
- Trevor Parscal (12/73) Jun 02 2005 What if i don't want to write all that? How to do import something into
- Phoenix (25/99) Jun 02 2005 i`ve found this in documentation:
- Carlos Santander (4/32) Jun 02 2005 That's new to me. Where's that?
- Ben Hinkle (3/5) Jun 02 2005 It worked fine for me. Are you sure the posted code errors for you?
Why is it that if I have a module that I am using to import other modules, it never works? foo.d ----------------------- module foo; int myfoo = 1; bar.d ----------------------- module bar; int mybar = 2; everything.d ---------------- module everything; public { import foo; import bar; } test.d ---------------------- import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; } ----------------------------- In my mind, this should output "12"... Instead I get test.d(6): identifier 'myfoo' is not defined test.d(6): identifier 'mybar' is not defined can someone tell my the trick to this? I hate having to update the imports of all the files all the time, so i want to centralize it... And how do you use / what do you use package { ... } for? The documentation on modules and packages seemed a little vague. -- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.com
Jun 02 2005
Trevor Parscal napsal(a):Why is it that if I have a module that I am using to import other modules, it never works? foo.d ----------------------- module foo; int myfoo = 1; bar.d ----------------------- module bar; int mybar = 2; everything.d ---------------- module everything; public { import foo; import bar; } test.d ---------------------- import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; } ----------------------------- In my mind, this should output "12"...i think, that the code should be import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(everything.foo.myfoo, everything.bar.mybar)); return 0; }Instead I get test.d(6): identifier 'myfoo' is not defined test.d(6): identifier 'mybar' is not defined can someone tell my the trick to this? I hate having to update the imports of all the files all the time, so i want to centralize it... And how do you use / what do you use package { ... } for? The documentation on modules and packages seemed a little vague.
Jun 02 2005
Phoenix wrote:Trevor Parscal napsal(a):What if i don't want to write all that? How to do import something into the public level? Isn't that what the public keyword is all about? I thought using "everything.foo.myfoo", or actually "foo.myfoo" (i believe is the actual way to do that) was only to make clear which one to use in the case of a name conflict... Any ideas?Why is it that if I have a module that I am using to import other modules, it never works? foo.d ----------------------- module foo; int myfoo = 1; bar.d ----------------------- module bar; int mybar = 2; everything.d ---------------- module everything; public { import foo; import bar; } test.d ---------------------- import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; } ----------------------------- In my mind, this should output "12"...i think, that the code should be import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(everything.foo.myfoo, everything.bar.mybar)); return 0; }-- Thanks, Trevor Parscal www.trevorparscal.com trevorparscal hotmail.comInstead I get test.d(6): identifier 'myfoo' is not defined test.d(6): identifier 'mybar' is not defined can someone tell my the trick to this? I hate having to update the imports of all the files all the time, so i want to centralize it... And how do you use / what do you use package { ... } for? The documentation on modules and packages seemed a little vague.
Jun 02 2005
Trevor Parscal napsal(a):Phoenix wrote:i`ve found this in documentation: import std.string; // std.string is added to the known scopes alias std.string.*; // alias all of std.string into the present scope (or it should be alias std.string.* *; ? i never tried this) everything.d ---------------- module everything; public { import foo; import bar; } alias foo.*; alias bar.*; main.d ---------------- import everything; alias everything.*; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; }Trevor Parscal napsal(a):What if i don't want to write all that? How to do import something into the public level? Isn't that what the public keyword is all about? I thought using "everything.foo.myfoo", or actually "foo.myfoo" (i believe is the actual way to do that) was only to make clear which one to use in the case of a name conflict... Any ideas?Why is it that if I have a module that I am using to import other modules, it never works? foo.d ----------------------- module foo; int myfoo = 1; bar.d ----------------------- module bar; int mybar = 2; everything.d ---------------- module everything; public { import foo; import bar; } test.d ---------------------- import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; } ----------------------------- In my mind, this should output "12"...i think, that the code should be import everything; import std.stdio; import std.string; int main(char[][] args) { writefln(format(everything.foo.myfoo, everything.bar.mybar)); return 0; }Instead I get test.d(6): identifier 'myfoo' is not defined test.d(6): identifier 'mybar' is not defined can someone tell my the trick to this? I hate having to update the imports of all the files all the time, so i want to centralize it... And how do you use / what do you use package { ... } for? The documentation on modules and packages seemed a little vague.
Jun 02 2005
Phoenix escribió:i`ve found this in documentation: import std.string; // std.string is added to the known scopes alias std.string.*; // alias all of std.string into the present scope (or it should be alias std.string.* *; ? i never tried this) everything.d ---------------- module everything; public { import foo; import bar; } alias foo.*; alias bar.*; main.d ---------------- import everything; alias everything.*; import std.stdio; import std.string; int main(char[][] args) { writefln(format(myfoo, mybar)); return 0; }That's new to me. Where's that? -- Carlos Santander Bernal
Jun 02 2005
"Trevor Parscal" <trevorparscal hotmail.com> wrote in message news:d7n3l1$1da4$1 digitaldaemon.com...Why is it that if I have a module that I am using to import other modules, it never works?It worked fine for me. Are you sure the posted code errors for you?
Jun 02 2005