Thread overview | ||||||||
---|---|---|---|---|---|---|---|---|
|
June 02, 2005 Public Imports? | ||||
---|---|---|---|---|
| ||||
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
|
June 02, 2005 Re: Public Imports? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trevor Parscal | 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. > |
June 02, 2005 Re: Public Imports? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phoenix | Phoenix wrote: > 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; > } 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? >> 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 |
June 02, 2005 Re: Public Imports? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trevor Parscal | Trevor Parscal napsal(a): > Phoenix wrote: > >> 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; >> } > > > 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? > 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; } >>> 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. >>> > |
June 02, 2005 Re: Public Imports? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trevor Parscal | "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? |
June 02, 2005 Re: Public Imports? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Phoenix | 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 |
Copyright © 1999-2021 by the D Language Foundation