Thread overview | |||||||
---|---|---|---|---|---|---|---|
|
September 20, 2002 Importing from the same package | ||||
---|---|---|---|---|
| ||||
Ok, I have a source file located at a/b/c.d. The first two lines are: module a.b.c; import a.b.foo; I figured that the compiler would recognize that they are in the same package (a.b), and thus open the file "foo.d" in the same directory. However, it doesn't work...apparently it tries to open "a/b/foo.d" instead. If I change the import statement to import "foo", then it works. So is my syntax wrong, or is this a compiler bug? |
September 21, 2002 Re: Importing from the same package | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russell Lewis | "Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D8BB5C1.4070700@deming-os.org... > Ok, I have a source file located at a/b/c.d. The first two lines are: > module a.b.c; > import a.b.foo; > > I figured that the compiler would recognize that they are in the same package (a.b), and thus open the file "foo.d" in the same directory. However, it doesn't work...apparently it tries to open "a/b/foo.d" instead. If I change the import statement to import "foo", then it works. So is my syntax wrong, or is this a compiler bug? That's the way it's supposed to work. Imports are always done relative to where the source file is. |
September 21, 2002 Re: Importing from the same package | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > "Russell Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D8BB5C1.4070700@deming-os.org... > > Ok, I have a source file located at a/b/c.d. The first two lines are: > > module a.b.c; > > import a.b.foo; > > > > I figured that the compiler would recognize that they are in the same package (a.b), and thus open the file "foo.d" in the same directory. However, it doesn't work...apparently it tries to open "a/b/foo.d" instead. If I change the import statement to import "foo", then it works. So is my syntax wrong, or is this a compiler bug? > > That's the way it's supposed to work. Imports are always done relative to where the source file is. I can see how it would be nice to be able to import something relative to the current position. But how then do we import something from some other package? If we are the file "a/b/c.d" (module a.b.c), then how do we import the module e.f.g, which is in the file "e/f/g.d"? -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
September 21, 2002 Re: Importing from the same package | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russ Lewis | "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D8C2D36.8B176132@deming-os.org... > > That's the way it's supposed to work. Imports are always done relative to > > where the source file is. > > I can see how it would be nice to be able to import something relative to the > current position. But how then do we import something from some other package? If we are the file "a/b/c.d" (module a.b.c), then how do we import > the module e.f.g, which is in the file "e/f/g.d"? Hmm. Looks like a problem :-( |
October 05, 2002 Re: Importing from the same package | ||||
---|---|---|---|---|
| ||||
Posted in reply to Walter | Walter wrote: > "Russ Lewis" <spamhole-2001-07-16@deming-os.org> wrote in message news:3D8C2D36.8B176132@deming-os.org... > > > That's the way it's supposed to work. Imports are always done relative > to > > > where the source file is. > > > > I can see how it would be nice to be able to import something relative to > the > > current position. But how then do we import something from some other package? If we are the file "a/b/c.d" (module a.b.c), then how do we > import > > the module e.f.g, which is in the file "e/f/g.d"? > > Hmm. Looks like a problem :-( The following works, at least on DLI 0.1.1: I have some code with the following modules: a.b; a.c; a.d.e; a.d.f; They all reside in that a/ directory, so their names, respectively, are: a/b.d a/c.d a/d/e.d a/d/f.d Things work fine for the a.b and a.c modules. The first lines of a/b.d are: module a.b; import a.c; import a.d.e; import a.d.f; and it find the correct sources just fine. However, the e.d source is problematic. What I'd like it to say is: module a.d.e; import a.d.f; If I build a/d/e.d from the a/d/ directory with the command cd a/d/; dli -c -g e.d; it doesn't work. However, I found that if I build from the a/ directory, it works! cd a/; dli -c -g d/e.d; Likewise, I can go to the root directory, and it works as well: cd /; dli -c -g a/d/e.d So it seems that the rule, at least for now (and this might not apply to the Win32 D compiler) is to build ALL sources from either the root directory or from one level below it (if all your sources are in the same root package). Then use fully qualified module names for all imports. -- The Villagers are Online! http://villagersonline.com .[ (the fox.(quick,brown)) jumped.over(the dog.lazy) ] .[ (a version.of(English).(precise.more)) is(possible) ] ?[ you want.to(help(develop(it))) ] |
Copyright © 1999-2021 by the D Language Foundation