www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Package explain

reply Zarathustra <adam.chrapkowski gmail.com> writes:
Could anybody explain what "package" exctly mean?

module package1.module1;
static int variable = 3;

module package1.module2;

module package1.module3;
package import package1.module1, package1.module2;

module main;
import package1.module3;

void main(){ 
  variable1 = 5;  // Why variable is accessable?
}

 |
 |--- main
 |--- package1
           |
           |--- module1
           |--- module2
           |--- module3

I'm dsss user.
Aug 21 2008
next sibling parent reply Jesse Phillips <jessekphillips gmail.com> writes:
On Thu, 21 Aug 2008 05:45:16 -0400, Zarathustra wrote:

 Could anybody explain what "package" exctly mean?
 
 module package1.module1;
 static int variable = 3;
 
 module package1.module2;
 
 module package1.module3;
 package import package1.module1, package1.module2;
 
 module main;
 import package1.module3;
 
 void main(){
   variable1 = 5;  // Why variable is accessable?
 }
 
  |
  |--- main
  |--- package1
            |
            |--- module1
            |--- module2
            |--- module3
 
 I'm dsss user.

I don't see anything in the docs about a package import. Public, Private, Static, but not Package.
Aug 21 2008
parent Ary Borenszweig <ary esperanto.org.ar> writes:
Jesse Phillips a écrit :
 On Thu, 21 Aug 2008 05:45:16 -0400, Zarathustra wrote:
 
 Could anybody explain what "package" exctly mean?

 module package1.module1;
 static int variable = 3;

 module package1.module2;

 module package1.module3;
 package import package1.module1, package1.module2;

 module main;
 import package1.module3;

 void main(){
   variable1 = 5;  // Why variable is accessable?
 }

  |
  |--- main
  |--- package1
            |
            |--- module1
            |--- module2
            |--- module3

 I'm dsss user.

I don't see anything in the docs about a package import. Public, Private, Static, but not Package.

Here goes my opinion about this again: any modifier that doesn't make sense in a given context, should be a compiler error. This thread is and example of what happens if this is not the case.
Aug 21 2008
prev sibling parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"Zarathustra" <adam.chrapkowski gmail.com> wrote in message 
news:g8jdfc$cqk$1 digitalmars.com...
 Could anybody explain what "package" exctly mean?

 module package1.module1;
 static int variable = 3;

"static" does not make variables private as in C. "private" does that. Declarations are implicitly public, hence why you can access it in main.
 module package1.module2;

 module package1.module3;
 package import package1.module1, package1.module2;

Yeah, what the hell is "package import"?
 module main;
 import package1.module3;

 void main(){
  variable1 = 5;  // Why variable is accessable?
 }

 |
 |--- main
 |--- package1
           |
           |--- module1
           |--- module2
           |--- module3

 I'm dsss user. 

Aug 21 2008
parent Fawzi Mohamed <fmohamed mac.com> writes:
On 2008-08-21 16:51:26 +0200, "Jarrett Billingsley" <kb3ctd2 yahoo.com> said:

 "Zarathustra" <adam.chrapkowski gmail.com> wrote in message
 news:g8jdfc$cqk$1 digitalmars.com...
 Could anybody explain what "package" exctly mean?
 
 module package1.module1;
 static int variable = 3;

"static" does not make variables private as in C. "private" does that. Declarations are implicitly public, hence why you can access it in main.

yes static int variable = 3; actually means public static int variable =3; if you write private static int variable =3; you can't access it from any other module if you write package static int variable =3; you can access it from module2 and module3 (that are in the same package) but not from main.
 
 module package1.module2;
 
 module package1.module3;
 package import package1.module1, package1.module2;

Yeah, what the hell is "package import"?

this is most likely not implemented, it is documented nowhere, you might expect it for symmetry reasons, but it is not there. If you think it should be there (and really I cannot think a good case in which you need it) try filing a bug report... Fawzi
 
 module main;
 import package1.module3;
 
 void main(){
 variable1 = 5;  // Why variable is accessable?
 }
 
 |
 |--- main
 |--- package1
 |
 |--- module1
 |--- module2
 |--- module3
 
 I'm dsss user.


Aug 21 2008