www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Package Import

reply DemmeGod <me demmegod.com> writes:
In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like Java's
method of packaging, however D's method seems somewhat cumbersome, since it
appears to me that all of a module's classes must be in a single file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?

Thanks in advance
Demme
May 10 2004
next sibling parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
DemmeGod wrote:

In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like Java's
method of packaging, however D's method seems somewhat cumbersome, since it
appears to me that all of a module's classes must be in a single file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?

Thanks in advance
Demme
  
What I would do to break things is put all the classes you need to be friends (normally quite rare), in the same module. Everything else can can go in other modules and you can link them together using import. -- -Anderson: http://badmama.com.au/~anderson/
May 11 2004
parent reply DemmeGod <me demmegod.com> writes:
J Anderson wrote:

 DemmeGod wrote:
 
In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like Java's
method of packaging, however D's method seems somewhat cumbersome, since
it
appears to me that all of a module's classes must be in a single file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?

Thanks in advance
Demme
  
What I would do to break things is put all the classes you need to be friends (normally quite rare), in the same module. Everything else can can go in other modules and you can link them together using import.
When you say link them together, how do you mean? Do you mean use a ton of imports in each file that is using them? Or is it possible to import modules into another module, which will in turn be imported when one wishes to use all of the modules? Thanks Demme
May 11 2004
parent J Anderson <REMOVEanderson badmama.com.au> writes:
DemmeGod wrote:

J Anderson wrote:

  

DemmeGod wrote:

    

In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like Java's
method of packaging, however D's method seems somewhat cumbersome, since
it
appears to me that all of a module's classes must be in a single file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?

Thanks in advance
Demme
 

      
What I would do to break things is put all the classes you need to be friends (normally quite rare), in the same module. Everything else can can go in other modules and you can link them together using import.
When you say link them together, how do you mean? Do you mean use a ton of imports in each file that is using them? Or is it possible to import modules into another module, which will in turn be imported when one wishes to use all of the modules? Thanks Demme
Yes just don't have the word private infront. -- -Anderson: http://badmama.com.au/~anderson/
May 11 2004
prev sibling parent reply "Phill" <phill pacific.net.au> writes:
A module is more or less a file.
You can have one module foreach class if you want.

Take a look at this URL:

http://www.digitalmars.com/d/module.html

Phill.

"DemmeGod" <me demmegod.com> wrote in message
news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like Java's
 method of packaging, however D's method seems somewhat cumbersome, since
it
 appears to me that all of a module's classes must be in a single file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
May 11 2004
parent reply DemmeGod <me demmegod.com> writes:
I've read the specs...  I understand that, however is one does it that way,
one must import each class that one indends on using.  My question was if
it was possible to import an entire class, that is import a whole bunch on
modules.  I take it that this is not possible?

Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.
 
 Take a look at this URL:
 
 http://www.digitalmars.com/d/module.html
 
 Phill.
 
 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like Java's
 method of packaging, however D's method seems somewhat cumbersome, since
it
 appears to me that all of a module's classes must be in a single file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
May 11 2004
next sibling parent reply Regan Heath <regan netwin.co.nz> writes:
On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:
 I've read the specs...  I understand that, however is one does it that 
 way, one must import each class that one indends on using.  My question 
 was if
 it was possible to import an entire class, that is import a whole bunch 
 on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
 Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.

 Take a look at this URL:

 http://www.digitalmars.com/d/module.html

 Phill.

 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like Java's
 method of packaging, however D's method seems somewhat cumbersome, 
 since
it
 appears to me that all of a module's classes must be in a single 
 file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
May 11 2004
parent reply DemmeGod <me demmegod.com> writes:
That's precisely what I mean... I get a compile error with something similar
to that, however.
I figure I'd write a lightweight logger:

[com/demmegod/lwLog4D.d]
module com.demmegod.lwLog4D;

import com.demmegod.lwLog4D.Logger;

[com/demmegod/lwLog4D/Logger.d]
module com.demmegod.lwLog4D.Logger;

import com.demmegod.lwLog4D;

class Logger
{
        Appender[] appenders = [];      
        static Logger globalLogger;
        
        static Logger getGlobalLogger()
        {
                ...
        }
        
        static void setGlobalLogger(Logger _globalLogger)
        {
                ...
        }
        
        this()
        {
                ...
        }
        
        void log(LogPriority priority, char[] message)
        {
                ...
        }
        
        void addAppender(Appender appender)
        {
                ...
        }
        
        void removeAppender(Appender appender)
        {
                ...
        }
}

...Plus more classes...

When I try to compile lwLog4D.d, I get the following error:
com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the same
name

I assumed that meant that I couldn't import com.demmegod.lwLog4D.Logger. 
I'd like to import com.demmegod.lwLog4D and have access to multiple classes
in separate files (Logger being one example.)

Yes, I know I'm violating convention by using upper case characters in the
module and package names... I'll change that.

Thanks

Regan Heath wrote:

 On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:
 I've read the specs...  I understand that, however is one does it that
 way, one must import each class that one indends on using.  My question
 was if
 it was possible to import an entire class, that is import a whole bunch
 on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
 Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.

 Take a look at this URL:

 http://www.digitalmars.com/d/module.html

 Phill.

 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like Java's
 method of packaging, however D's method seems somewhat cumbersome,
 since
it
 appears to me that all of a module's classes must be in a single
 file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
May 11 2004
next sibling parent reply Regan Heath <regan netwin.co.nz> writes:
What are you writing it in? I am using DIDE which works quite well, you 
can get it here:
   http://www.atari-soldiers.com/dide.html

Here is a cut down code sample that compiles and runs, it does what you 
are trying to do (I think):

[test.d]
import std.string;
import com.demmegod.module2;

int main () {
	Module2 m = new Module2();
	m.m(0);
	return 0;
}

[/com/demmegod/module2.d]
module com.demmegod.module2;
import com.demmegod.module3;

class Module2 {
	void m(int a) {
		printf("module2: %d\n",a);
		if ( a < 100 ) {
			Module3 m = new Module3();
			m.m(++a);
		}
	}
}

[/com/demmegod/module3.d]
module com.demmegod.module3;
import com.demmegod.module2;

class Module3 {
	void m(int a) {
		printf("module3: %d\n",a);
		if ( a < 100 ) {
			Module2 m = new Module2();
			m.m(++a);
		}
	}
}

Regan.

On Tue, 11 May 2004 20:04:32 -0400, DemmeGod <me demmegod.com> wrote:
 That's precisely what I mean... I get a compile error with something 
 similar to that, however.
 I figure I'd write a lightweight logger:

 [com/demmegod/lwLog4D.d]
 module com.demmegod.lwLog4D;

 import com.demmegod.lwLog4D.Logger;

 [com/demmegod/lwLog4D/Logger.d]
 module com.demmegod.lwLog4D.Logger;

 import com.demmegod.lwLog4D;

 class Logger
 {
         Appender[] appenders = [];
         static Logger globalLogger;

         static Logger getGlobalLogger()
         {
                 ...
         }

         static void setGlobalLogger(Logger _globalLogger)
         {
                 ...
         }

         this()
         {
                 ...
         }

         void log(LogPriority priority, char[] message)
         {
                 ...
         }

         void addAppender(Appender appender)
         {
                 ...
         }

         void removeAppender(Appender appender)
         {
                 ...
         }
 }

 ...Plus more classes...

 When I try to compile lwLog4D.d, I get the following error:
 com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the 
 same
 name

 I assumed that meant that I couldn't import com.demmegod.lwLog4D.Logger.
 I'd like to import com.demmegod.lwLog4D and have access to multiple 
 classes
 in separate files (Logger being one example.)

 Yes, I know I'm violating convention by using upper case characters in 
 the
 module and package names... I'll change that.

 Thanks

 Regan Heath wrote:

 On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:
 I've read the specs...  I understand that, however is one does it that
 way, one must import each class that one indends on using.  My question
 was if
 it was possible to import an entire class, that is import a whole bunch
 on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
 Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.

 Take a look at this URL:

 http://www.digitalmars.com/d/module.html

 Phill.

 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like 
 Java's
 method of packaging, however D's method seems somewhat cumbersome,
 since
it
 appears to me that all of a module's classes must be in a single
 file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
May 11 2004
parent reply DemmeGod <me demmegod.com> writes:
Thats not quite accurate... You'll get a compile error if you move module3
to com.demmegod.module2.module3.

DIDE looks nice, but it also looks like it's Windows only.  I'm Linux and
OSX only.

Thanks

Regan Heath wrote:

 What are you writing it in? I am using DIDE which works quite well, you
 can get it here:
    http://www.atari-soldiers.com/dide.html
 
 Here is a cut down code sample that compiles and runs, it does what you
 are trying to do (I think):
 
 [test.d]
 import std.string;
 import com.demmegod.module2;
 
 int main () {
 Module2 m = new Module2();
 m.m(0);
 return 0;
 }
 
 [/com/demmegod/module2.d]
 module com.demmegod.module2;
 import com.demmegod.module3;
 
 class Module2 {
 void m(int a) {
 printf("module2: %d\n",a);
 if ( a < 100 ) {
 Module3 m = new Module3();
 m.m(++a);
 }
 }
 }
 
 [/com/demmegod/module3.d]
 module com.demmegod.module3;
 import com.demmegod.module2;
 
 class Module3 {
 void m(int a) {
 printf("module3: %d\n",a);
 if ( a < 100 ) {
 Module2 m = new Module2();
 m.m(++a);
 }
 }
 }
 
 Regan.
 
 On Tue, 11 May 2004 20:04:32 -0400, DemmeGod <me demmegod.com> wrote:
 That's precisely what I mean... I get a compile error with something
 similar to that, however.
 I figure I'd write a lightweight logger:

 [com/demmegod/lwLog4D.d]
 module com.demmegod.lwLog4D;

 import com.demmegod.lwLog4D.Logger;

 [com/demmegod/lwLog4D/Logger.d]
 module com.demmegod.lwLog4D.Logger;

 import com.demmegod.lwLog4D;

 class Logger
 {
         Appender[] appenders = [];
         static Logger globalLogger;

         static Logger getGlobalLogger()
         {
                 ...
         }

         static void setGlobalLogger(Logger _globalLogger)
         {
                 ...
         }

         this()
         {
                 ...
         }

         void log(LogPriority priority, char[] message)
         {
                 ...
         }

         void addAppender(Appender appender)
         {
                 ...
         }

         void removeAppender(Appender appender)
         {
                 ...
         }
 }

 ...Plus more classes...

 When I try to compile lwLog4D.d, I get the following error:
 com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the
 same
 name

 I assumed that meant that I couldn't import com.demmegod.lwLog4D.Logger.
 I'd like to import com.demmegod.lwLog4D and have access to multiple
 classes
 in separate files (Logger being one example.)

 Yes, I know I'm violating convention by using upper case characters in
 the
 module and package names... I'll change that.

 Thanks

 Regan Heath wrote:

 On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:
 I've read the specs...  I understand that, however is one does it that
 way, one must import each class that one indends on using.  My question
 was if
 it was possible to import an entire class, that is import a whole bunch
 on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
 Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.

 Take a look at this URL:

 http://www.digitalmars.com/d/module.html

 Phill.

 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is it
 possible to break up a module into several files?  I rather like
 Java's
 method of packaging, however D's method seems somewhat cumbersome,
 since
it
 appears to me that all of a module's classes must be in a single
 file.  I
 don't trust my version control system's merging algorithm that much.

 Or am I completely missing something, as a D newbie?
May 11 2004
parent Regan Heath <regan netwin.co.nz> writes:
On Tue, 11 May 2004 21:00:58 -0400, DemmeGod <me demmegod.com> wrote:
 Thats not quite accurate... You'll get a compile error if you move 
 module3 to com.demmegod.module2.module3.
Indeed, an "import com package and module have the same name" error. You can get rid of that by renaming either the directory (AKA the package) or the module (AKA the file).
 DIDE looks nice, but it also looks like it's Windows only.  I'm Linux and
 OSX only.
Ahh.. oh well. Regan.
 Thanks

 Regan Heath wrote:

 What are you writing it in? I am using DIDE which works quite well, you
 can get it here:
    http://www.atari-soldiers.com/dide.html

 Here is a cut down code sample that compiles and runs, it does what you
 are trying to do (I think):

 [test.d]
 import std.string;
 import com.demmegod.module2;

 int main () {
 Module2 m = new Module2();
 m.m(0);
 return 0;
 }

 [/com/demmegod/module2.d]
 module com.demmegod.module2;
 import com.demmegod.module3;

 class Module2 {
 void m(int a) {
 printf("module2: %d\n",a);
 if ( a < 100 ) {
 Module3 m = new Module3();
 m.m(++a);
 }
 }
 }

 [/com/demmegod/module3.d]
 module com.demmegod.module3;
 import com.demmegod.module2;

 class Module3 {
 void m(int a) {
 printf("module3: %d\n",a);
 if ( a < 100 ) {
 Module2 m = new Module2();
 m.m(++a);
 }
 }
 }

 Regan.

 On Tue, 11 May 2004 20:04:32 -0400, DemmeGod <me demmegod.com> wrote:
 That's precisely what I mean... I get a compile error with something
 similar to that, however.
 I figure I'd write a lightweight logger:

 [com/demmegod/lwLog4D.d]
 module com.demmegod.lwLog4D;

 import com.demmegod.lwLog4D.Logger;

 [com/demmegod/lwLog4D/Logger.d]
 module com.demmegod.lwLog4D.Logger;

 import com.demmegod.lwLog4D;

 class Logger
 {
         Appender[] appenders = [];
         static Logger globalLogger;

         static Logger getGlobalLogger()
         {
                 ...
         }

         static void setGlobalLogger(Logger _globalLogger)
         {
                 ...
         }

         this()
         {
                 ...
         }

         void log(LogPriority priority, char[] message)
         {
                 ...
         }

         void addAppender(Appender appender)
         {
                 ...
         }

         void removeAppender(Appender appender)
         {
                 ...
         }
 }

 ...Plus more classes...

 When I try to compile lwLog4D.d, I get the following error:
 com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the
 same
 name

 I assumed that meant that I couldn't import 
 com.demmegod.lwLog4D.Logger.
 I'd like to import com.demmegod.lwLog4D and have access to multiple
 classes
 in separate files (Logger being one example.)

 Yes, I know I'm violating convention by using upper case characters in
 the
 module and package names... I'll change that.

 Thanks

 Regan Heath wrote:

 On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:
 I've read the specs...  I understand that, however is one does it 
 that
 way, one must import each class that one indends on using.  My 
 question
 was if
 it was possible to import an entire class, that is import a whole 
 bunch
 on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
 Phill wrote:

 A module is more or less a file.
 You can have one module foreach class if you want.

 Take a look at this URL:

 http://www.digitalmars.com/d/module.html

 Phill.

 "DemmeGod" <me demmegod.com> wrote in message
 news:c7pnss$28ea$1 digitaldaemon.com...
 In D, is it possible to import an entire package?  Better yet, is 
 it
 possible to break up a module into several files?  I rather like
 Java's
 method of packaging, however D's method seems somewhat cumbersome,
 since
it
 appears to me that all of a module's classes must be in a single
 file.  I
 don't trust my version control system's merging algorithm that 
 much.

 Or am I completely missing something, as a D newbie?
-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
May 11 2004
prev sibling parent reply J C Calvarese <jcc7 cox.net> writes:
DemmeGod wrote:
 That's precisely what I mean... I get a compile error with something similar
 to that, however.
 I figure I'd write a lightweight logger:
 
 [com/demmegod/lwLog4D.d]
 module com.demmegod.lwLog4D;
 
 import com.demmegod.lwLog4D.Logger;
 
 [com/demmegod/lwLog4D/Logger.d]
 module com.demmegod.lwLog4D.Logger;
There's a limitation in the way D's modules work: you can't have a folder and a .d file with the same name in your import scheme. (I don't think this limitation is documented in the spec.) I don't know if Walter is convinced it has to be this way, but others have run into this same situation. If you change it, it'll work. [com/demmegod/lwLog4D.d] --> [com/demmegod/lwLog4D/main.d] module com.demmegod.lwLog4D; --> module com.demmegod.lwLog4D.main; If you don't change it, it won't work. If you have to have it as you originally wrote it, I'd recommend posting a bug report in digitalmars.d.bugs (and it wouldn't hurt to explain why you need this specific arrangement).
 
 import com.demmegod.lwLog4D;
 
 class Logger
 {
         Appender[] appenders = [];      
         static Logger globalLogger;
         
         static Logger getGlobalLogger()
         {
                 ...
         }
         
         static void setGlobalLogger(Logger _globalLogger)
         {
                 ...
         }
         
         this()
         {
                 ...
         }
         
         void log(LogPriority priority, char[] message)
         {
                 ...
         }
         
         void addAppender(Appender appender)
         {
                 ...
         }
         
         void removeAppender(Appender appender)
         {
                 ...
         }
 }
 
 ...Plus more classes...
 
 When I try to compile lwLog4D.d, I get the following error:
 com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the same
 name
 
 I assumed that meant that I couldn't import com.demmegod.lwLog4D.Logger. 
 I'd like to import com.demmegod.lwLog4D and have access to multiple classes
 in separate files (Logger being one example.)
 
 Yes, I know I'm violating convention by using upper case characters in the
 module and package names... I'll change that.
 
 Thanks
 
 Regan Heath wrote:
 
 
On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:

I've read the specs...  I understand that, however is one does it that
way, one must import each class that one indends on using.  My question
was if
it was possible to import an entire class, that is import a whole bunch
on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
Phill wrote:


A module is more or less a file.
You can have one module foreach class if you want.

Take a look at this URL:

http://www.digitalmars.com/d/module.html

Phill.

"DemmeGod" <me demmegod.com> wrote in message
news:c7pnss$28ea$1 digitaldaemon.com...

In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like Java's
method of packaging, however D's method seems somewhat cumbersome,
since
it
appears to me that all of a module's classes must be in a single
file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?
-- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
May 11 2004
parent DemmeGod <me demmegod.com> writes:
No, I don't need to have it that way, I'd just prefer it.  I haven't seen
anything in the specs about that limitation, so I'll post a bug report
about it.

Thanks Guys

J C Calvarese wrote:

 DemmeGod wrote:
 That's precisely what I mean... I get a compile error with something
 similar to that, however.
 I figure I'd write a lightweight logger:
 
 [com/demmegod/lwLog4D.d]
 module com.demmegod.lwLog4D;
 
 import com.demmegod.lwLog4D.Logger;
 
 [com/demmegod/lwLog4D/Logger.d]
 module com.demmegod.lwLog4D.Logger;
There's a limitation in the way D's modules work: you can't have a folder and a .d file with the same name in your import scheme. (I don't think this limitation is documented in the spec.) I don't know if Walter is convinced it has to be this way, but others have run into this same situation. If you change it, it'll work. [com/demmegod/lwLog4D.d] --> [com/demmegod/lwLog4D/main.d] module com.demmegod.lwLog4D; --> module com.demmegod.lwLog4D.main; If you don't change it, it won't work. If you have to have it as you originally wrote it, I'd recommend posting a bug report in digitalmars.d.bugs (and it wouldn't hurt to explain why you need this specific arrangement).
 
 import com.demmegod.lwLog4D;
 
 class Logger
 {
         Appender[] appenders = [];
         static Logger globalLogger;
         
         static Logger getGlobalLogger()
         {
                 ...
         }
         
         static void setGlobalLogger(Logger _globalLogger)
         {
                 ...
         }
         
         this()
         {
                 ...
         }
         
         void log(LogPriority priority, char[] message)
         {
                 ...
         }
         
         void addAppender(Appender appender)
         {
                 ...
         }
         
         void removeAppender(Appender appender)
         {
                 ...
         }
 }
 
 ...Plus more classes...
 
 When I try to compile lwLog4D.d, I get the following error:
 com/demmegod/lwLog4D.d(1): module lwLog4D module and package have the
 same name
 
 I assumed that meant that I couldn't import com.demmegod.lwLog4D.Logger.
 I'd like to import com.demmegod.lwLog4D and have access to multiple
 classes in separate files (Logger being one example.)
 
 Yes, I know I'm violating convention by using upper case characters in
 the module and package names... I'll change that.
 
 Thanks
 
 Regan Heath wrote:
 
 
On Tue, 11 May 2004 13:23:59 -0400, DemmeGod <me demmegod.com> wrote:

I've read the specs...  I understand that, however is one does it that
way, one must import each class that one indends on using.  My question
was if
it was possible to import an entire class, that is import a whole bunch
on modules.  I take it that this is not possible?
You mean something like this... import module1; [test.d] import std.string; import module1; int main () { m1(5); m2(8); m3(9); return 0; } [module1.d] module module1; import module2; import module3; void m1(int a) { printf("module1: %d\n",a); m2(++a); m3(++a); } [module2.d] module module2; void m2(int a) { printf("module2: %d\n",a); } [module3.d] module module3; void m3(int a) { printf("module3: %d\n",a); } i.e. importing module1 implicitly imports modules 2 and 3. Regan.
Phill wrote:


A module is more or less a file.
You can have one module foreach class if you want.

Take a look at this URL:

http://www.digitalmars.com/d/module.html

Phill.

"DemmeGod" <me demmegod.com> wrote in message
news:c7pnss$28ea$1 digitaldaemon.com...

In D, is it possible to import an entire package?  Better yet, is it
possible to break up a module into several files?  I rather like
Java's method of packaging, however D's method seems somewhat
cumbersome, since
it
appears to me that all of a module's classes must be in a single
file.  I
don't trust my version control system's merging algorithm that much.

Or am I completely missing something, as a D newbie?
May 11 2004
prev sibling parent "Phill" <phill pacific.net.au> writes:
"DemmeGod" <me demmegod.com> wrote in message
news:c7r27f$15qf$1 digitaldaemon.com...
 I've read the specs...  I understand that, however is one does it that
way,
 one must import each class that one indends on using.  My question was if
 it was possible to import an entire class, that is import a whole bunch on
 modules.  I take it that this is not possible?
If you mean you want to import "a whole bunch of modules" then Regans way is the way to go.
May 11 2004