www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - How to explicitly qualify my modules with the package

reply Andy Little <andy servocomm.freeserve.co.uk> writes:
Cant figure out how the package qualifier should work or what syntax I should
use to get it working.

E.g.

Where gcd is defined in sub-dir meta of this-file source dir as:
/*
"D:/projects/dmd/meta/mod_gcd.d"
//------------------------------------------------------
module meta.mod_gcd;

template gcd( T, T N, T D){
   static if (D== 0){
      static const T value = N;
   }
   else {
      static const T value = gcd!(T,D, (N % D)).value;
   }
}
//------------------------------------------------------
*/

static import std.stdio;
// works ok...
static if(1){
   static const bool USE_PACKAGE_QUALIFIER =false;

   import meta.mod_gcd;

}

else {
/* in this path compilation fails with:

D:\Projects\dmd>dmd -c test1.d
test1.d(49): Error: template identifier gcd is not a member of meta
Error: no property 'value' for type 'int'
*/

   static const int USE_PACKAGE_QUALIFIER =true;

   static import meta.mod_gcd;

}



int main(char[][] args)
{
   static if(USE_PACKAGE_QUALIFIER){



   }
   else{
      std.stdio.writefln("%d\n",gcd!(int,8,64).value);
   }

   return 0;
}
Mar 04 2007
parent reply Daniel Keep <daniel.keep.lists gmail.com> writes:
Andy Little wrote:
 Cant figure out how the package qualifier should work or what syntax I should
use to get it working.
 
 E.g.
 
 Where gcd is defined in sub-dir meta of this-file source dir as:
 /*
 "D:/projects/dmd/meta/mod_gcd.d"
 //------------------------------------------------------
 module meta.mod_gcd;
 
 template gcd( T, T N, T D){
    static if (D== 0){
       static const T value = N;
    }
    else {
       static const T value = gcd!(T,D, (N % D)).value;
    }
 }
 //------------------------------------------------------
 */
 
 static import std.stdio;
 // works ok...
 static if(1){
    static const bool USE_PACKAGE_QUALIFIER =false;

    import meta.mod_gcd;

 }
 
 else {
 /* in this path compilation fails with:
 
 D:\Projects\dmd>dmd -c test1.d
 test1.d(49): Error: template identifier gcd is not a member of meta
 Error: no property 'value' for type 'int'
 */
 
    static const int USE_PACKAGE_QUALIFIER =true;

    static import meta.mod_gcd;

 }
 
 
 
 int main(char[][] args)
 {
    static if(USE_PACKAGE_QUALIFIER){


This fails because gcd is in the 'meta.mod_gcd' module. It would be like saying 'std.writefln'.

    }
    else{
       std.stdio.writefln("%d\n",gcd!(int,8,64).value);
    }
 
    return 0;
 }
-- Unlike Knuth, I have neither proven or tried the above; it may not even make sense. v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP http://hackerkey.com/
Mar 04 2007
parent Andy Little <andy servocomm.freeserve.co.uk> writes:
Daniel Keep Wrote:

<...>

 This fails because gcd is in the 'meta.mod_gcd' module.  It would be
 like saying 'std.writefln'.
Aha. Thanks for switching on the light ! regards Andy Little
Mar 04 2007