July 25, 2004
I'm a bit confused by the whole argument going on here, but let me see if I'm understanding this correctly(probably not, but we'll see):


//////////////////////////////////////////
class FileConduit : Conduit
{
   private import std.c.linux.linux;
   private int handle;

   void close ()
   {
      std.c.linux.linux.close (handle);
   }
   void read (char[] dst)
   {
      std.linux.linux.read (handle, dst, dst.length);
   }
}
//////////////////////////////////////////
By having the import inside of the class, he's importing those C close
and read functions into the FileConduit namespace.  But they're also in
their own namespace still?  This by calling FileConduit.close() it tries
to call the C versions?

If this is the case:

Can std.c.linux.linux.close() be used without importing that module?  If not, what exactly does import do?



In C++ you must include the file, and then you have the option of providing the full 'name' to the function.  But if you do using, then you import that namespaces into a list of searchable namespaces when the full name isn't provided.

Sorry about the poor terminology, I'm no CS major.  But here's what I
mean:
///////////////////////////////////////////
#include <iostream>  // Now i can use std.cout and what not.

using namespace std;
// Tells the compiler to add this namespace to be searched if it can't
find something locally.


// Now I can do:
cout << "hello world!";
///////////////////////////////////////////

It seems in D, import is both a using, and an include all rolled into one.  Is there some way to exclude the imported module's namespace from automatically being searched?
July 25, 2004
Sha Chancellor wrote:
> I'm a bit confused by the whole argument going on here, but let me see if I'm understanding this correctly(probably not, but we'll see):

It's a confusing issue. I think I'm still confused.

> 
> 
> //////////////////////////////////////////
> class FileConduit : Conduit
> {
>    private import std.c.linux.linux;
>    private int handle;
>       void close ()
>    {
>       std.c.linux.linux.close (handle);
>    }
>    void read (char[] dst)
>    {
>       std.linux.linux.read (handle, dst, dst.length);
>    }
> }
> //////////////////////////////////////////
> By having the import inside of the class, he's importing those C close and read functions into the FileConduit namespace.  But they're also in their own namespace still?  This by calling FileConduit.close() it tries to call the C versions?
> 
> If this is the case:
> 
> Can std.c.linux.linux.close() be used without importing that module?  If not, what exactly does import do?

It doesn't have to be imported within the class. Importing outside of the class should work fine:

private import std.c.linux.linux;

class FileConduit : Conduit
{
    private int handle;

Previously, there have been some "forward reference" problems that were solved by moving the import into the class, but it was a work-around which (as we now know) has some troublesome side effects. I haven't heard yet if DMD 0.96 still generates forward reference errors, but I think it's better to simply fix those fwd ref problems that rewrite all of the inheritance rules.

-- 
Justin (a/k/a jcc7)
http://jcc_7.tripod.com/d/