www.digitalmars.com         C & C++   DMDScript  

D - import packages

reply "Pavel Minayev" <evilone omen.ru> writes:
Is it possible to import the entire package, with all its subpackages
and modules? The following doesn't work (yet?):

    import c;    // stdio & stdlib

    int main()
    {
        printf("Hello, world!\n");
        return 0;
    }

Are you planning to support this feature?
Feb 24 2002
next sibling parent reply "Walter" <walter digitalmars.com> writes:
At the moment, no. I think it's better to explicitly list the ones imported.

"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5ai6p$4q8$1 digitaldaemon.com...
 Is it possible to import the entire package, with all its subpackages
 and modules? The following doesn't work (yet?):

     import c;    // stdio & stdlib

     int main()
     {
         printf("Hello, world!\n");
         return 0;
     }

 Are you planning to support this feature?

Feb 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5aogs$7df$1 digitaldaemon.com...

 At the moment, no. I think it's better to explicitly list the ones

Not really. Suppose an opengl package with modules like gl, glu and glut. Rather than importing them all one by one, a simple "import opengl" would do the job... and imagine the package with 20-30 modules (a huge GUI library, or a DB toolkit might be such)...
Feb 24 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5avc3$akd$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a5aogs$7df$1 digitaldaemon.com...

 At the moment, no. I think it's better to explicitly list the ones

Not really. Suppose an opengl package with modules like gl, glu and glut. Rather than importing them all one by one, a simple "import opengl" would do the job... and imagine the package with 20-30 modules (a huge GUI library, or a DB toolkit might be such)...

Whoever wrote that should then supply an import that simply imports all the other imports!
Feb 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5b95o$f0a$1 digitaldaemon.com...

 Whoever wrote that should then supply an import that simply imports all

 other imports!

So it is legal to have both the package opengl and module opengl.d?
Feb 24 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5bbmc$g9m$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a5b95o$f0a$1 digitaldaemon.com...

 Whoever wrote that should then supply an import that simply imports all

 other imports!

So it is legal to have both the package opengl and module opengl.d?

No, they'd have to have different names.
Feb 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5bkgb$km2$1 digitaldaemon.com...

 So it is legal to have both the package opengl and module opengl.d?

No, they'd have to have different names.

Why? If you cannot import the package by its name anyhow, what's the problem with having a module with such a name?
Feb 24 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5cg4p$10qg$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a5bkgb$km2$1 digitaldaemon.com...

 So it is legal to have both the package opengl and module opengl.d?

No, they'd have to have different names.

Why? If you cannot import the package by its name anyhow, what's the problem with having a module with such a name?

I guess I'm not sure what you mean. Do you want to have this work: import foo; import foo.bar; ?
Feb 24 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5cp04$15bt$1 digitaldaemon.com...

 I guess I'm not sure what you mean. Do you want to have this work:

     import foo;
     import foo.bar;

 ?

Absolutely. Since package foo is simply a directory "foo", and module foo is a file "foo.d", it should work just fine.
Feb 25 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5d1ti$1b0j$1 digitaldaemon.com...
 "Walter" <walter digitalmars.com> wrote in message
 news:a5cp04$15bt$1 digitaldaemon.com...
 I guess I'm not sure what you mean. Do you want to have this work:
     import foo;
     import foo.bar;
 ?

module foo is a file "foo.d", it should work just fine.

But that would be analogous to: struct foo { int bar; } int foo; foo.bar + foo;
Feb 25 2002
parent reply "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5drkl$1nbf$1 digitaldaemon.com...

 But that would be analogous to:

     struct foo { int bar; }
     int foo;

     foo.bar + foo;

Then, we return back to the first post =) Some way to import the entire package by specifying its name.
Feb 25 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Pavel Minayev" <evilone omen.ru> wrote in message
news:a5dss1$1nri$1 digitaldaemon.com...
 Then, we return back to the first post =)
 Some way to import the entire package by specifying its name.

file.d: ----- import foo; foo.d: ------ import bar; import silly; import abc;
Feb 25 2002
parent "Pavel Minayev" <evilone omen.ru> writes:
"Walter" <walter digitalmars.com> wrote in message
news:a5eqea$268u$1 digitaldaemon.com...
 "Pavel Minayev" <evilone omen.ru> wrote in message
 news:a5dss1$1nri$1 digitaldaemon.com...
 Then, we return back to the first post =)
 Some way to import the entire package by specifying its name.


So if the package is named "foo", "import foo" would import all modules from it.
 file.d:
 -----
     import foo;

 foo.d:
 ------
     import bar;
     import silly;
     import abc;

Feb 25 2002
prev sibling parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
"Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje
news:a5ai6p$4q8$1 digitaldaemon.com...
| Is it possible to import the entire package, with all its subpackages
| and modules? The following doesn't work (yet?):
|
|     import c;    // stdio & stdlib
|
|     int main()
|     {
|         printf("Hello, world!\n");
|         return 0;
|     }
|
| Are you planning to support this feature?
|
|

"Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje
news:a5f5b6$2aik$1 digitaldaemon.com...
| "Walter" <walter digitalmars.com> wrote in message
| news:a5eqea$268u$1 digitaldaemon.com...
| > "Pavel Minayev" <evilone omen.ru> wrote in message
| > news:a5dss1$1nri$1 digitaldaemon.com...
| > > Then, we return back to the first post =)
| > > Some way to import the entire package by specifying its name.
|                                           ^^^^^^^^^^^^^^^^^^^^^^
|
| So if the package is named "foo", "import foo" would import all
| modules from it.
|
| > file.d:
| > -----
| >     import foo;
| >
| > foo.d:
| > ------
| >     import bar;
| >     import silly;
| >     import abc;
| >

(I won't explain how I got to this)
What happened to this? Walter, you never said anything about it. I'm
thinking 'import foo.*;' could be a work-around for that.

—————————————————————————
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.463 / Virus Database: 262 - Release Date: 2003-03-17
Mar 22 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5k80a$11ia$1 digitaldaemon.com...
 "Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje
 news:a5ai6p$4q8$1 digitaldaemon.com...
 | Is it possible to import the entire package, with all its subpackages
 | and modules? The following doesn't work (yet?):
 |
 |     import c;    // stdio & stdlib
 |
 |     int main()
 |     {
 |         printf("Hello, world!\n");
 |         return 0;
 |     }
 |
 | Are you planning to support this feature?
 |
 |

 "Pavel Minayev" <evilone omen.ru> escribiσ en el mensaje
 news:a5f5b6$2aik$1 digitaldaemon.com...
 | "Walter" <walter digitalmars.com> wrote in message
 | news:a5eqea$268u$1 digitaldaemon.com...
 | > "Pavel Minayev" <evilone omen.ru> wrote in message
 | > news:a5dss1$1nri$1 digitaldaemon.com...
 | > > Then, we return back to the first post =)
 | > > Some way to import the entire package by specifying its name.
 |                                           ^^^^^^^^^^^^^^^^^^^^^^
 |
 | So if the package is named "foo", "import foo" would import all
 | modules from it.
 |
 | > file.d:
 | > -----
 | >     import foo;
 | >
 | > foo.d:
 | > ------
 | >     import bar;
 | >     import silly;
 | >     import abc;
 | >

 (I won't explain how I got to this)
 What happened to this? Walter, you never said anything about it. I'm
 thinking 'import foo.*;' could be a work-around for that.

I thought it was clear - a 'package' can contain others simply by importing them, a-la the foo.d above. An import of foo gets all of foo's imports.
Mar 25 2003
parent reply "Carlos Santander B." <carlos8294 msn.com> writes:
| > | > file.d:
| > | > -----
| > | >     import foo;
| > | >
| > | > foo.d:
| > | > ------
| > | >     import bar;
| > | >     import silly;
| > | >     import abc;
|
| I thought it was clear - a 'package' can contain others simply by
importing
| them, a-la the foo.d above. An import of foo gets all of foo's imports.

I understand that, but what if module foo had a thousand files? Then foo.d
would have a thousand import lines.
I just tried this:
\
|-e.d
|-a\
   |-a.d
   |-b.d
   |-c.d
   |-d.d
a.d imports b,c and d. e.d imports a.a. If I do 'dmd -c e', I get:
"Assertion failure: '0' on line 342 in file 'module.c'", so the foo.d above
wouldn't work either.

—————————————————————————
Carlos Santander


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.465 / Virus Database: 263 - Release Date: 2003-03-25
Mar 25 2003
parent reply "Walter" <walter digitalmars.com> writes:
"Carlos Santander B." <carlos8294 msn.com> wrote in message
news:b5r0rg$2kec$1 digitaldaemon.com...
 | I thought it was clear - a 'package' can contain others simply by
 importing
 | them, a-la the foo.d above. An import of foo gets all of foo's imports.
 I understand that, but what if module foo had a thousand files? Then foo.d
 would have a thousand import lines.

Yes, it would. But forgive me, I think that a module that needs to import a thousand other modules has more pressing problems <g>.
 I just tried this:
 \
 |-e.d
 |-a\
    |-a.d
    |-b.d
    |-c.d
    |-d.d
 a.d imports b,c and d. e.d imports a.a. If I do 'dmd -c e', I get:
 "Assertion failure: '0' on line 342 in file 'module.c'", so the foo.d

 wouldn't work either.

Yes, having a module with the same name as its subdirectory doesn't work.
Mar 25 2003
parent reply Helmut Leitner <leitner hls.via.at> writes:
Walter wrote:
 
 "Carlos Santander B." <carlos8294 msn.com> wrote in message
 news:b5r0rg$2kec$1 digitaldaemon.com...
 | I thought it was clear - a 'package' can contain others simply by
 importing
 | them, a-la the foo.d above. An import of foo gets all of foo's imports.
 I understand that, but what if module foo had a thousand files? Then foo.d
 would have a thousand import lines.

Yes, it would.

Does that mean that a "just import" module can act as a replacement for a "central header" file? As there a different way to import a whole library or would such a module be the way to go? -- Helmut Leitner leitner hls.via.at Graz, Austria www.hls-software.com
Mar 26 2003
parent "Walter" <walter digitalmars.com> writes:
"Helmut Leitner" <leitner hls.via.at> wrote in message
news:3E8170D8.4586F4F9 hls.via.at...
 Walter wrote:
 "Carlos Santander B." <carlos8294 msn.com> wrote in message
 news:b5r0rg$2kec$1 digitaldaemon.com...
 | I thought it was clear - a 'package' can contain others simply by
 importing
 | them, a-la the foo.d above. An import of foo gets all of foo's



 I understand that, but what if module foo had a thousand files? Then



 would have a thousand import lines.

Yes, it would.

Does that mean that a "just import" module can act as a replacement for a "central header" file?

Yes.
 As there a different way to import a whole library or
 would such a module be the way to go?

The latter.
Mar 26 2003