Re: Proposal for Include files/headers

edA-qa wrote:
> Uggh, the world of XML comes to make something simple extremely robust. 
>  Since, for the most part, people will be using files to define 
> namespaces and classes, I suggest a simpler format which must be 
> supported by default:
> 
>     namespace MySpace = file( "dir/dir/file.h2" ) {
>         class MyClass = file( "dir/dir/file.h2" );
>     }
> 

Indeed, the above is far more readable.

> Here is where my intent differed from users.  I do not intend for 
> "import" to move things out of their namespace, that would cause the 
> same sort of name clashes that exist in Java.
> 
> What you are proposing is that "using" does both the "import" and the 
> "using" directive. While this may be convenient it has many pitfalls 
> for name clashes, consider first in my syntax:

Let me clarify. One could use qualified names, in which case "using" 
could be omitted and name clashes prevented. In other words, you don't 
need to write "using" if you plan on explicitly qualifying a type.

Also, I opt for importing namespaces and not individual classes because 
we *want* to pull any free functions, such as operator+, defined for 
those classes.  In order to make it safe and efficient, we would have to 
go away from the existing C++ practice, where, for example, an entire 
std. library is in one namespace. A given bottom-level namespace would 
have a single type (primary) and any free functions defined for it. Here 
is a String type written in this fashion:

namespace Std
{
   namespace String
   {
     class String           // primary member of this namespace
     { ... };

     String operator+ (String const&& lhs, String const&& rhs);
   }
}

// user's file
//
using Std;

{
   String.String s1, s2;  // Explicit type qualification.
   ...

   String.String s3 = s1 + s2;  // error, operator+ not visible

   {
     using String;  // brings String namespace to this scope only

     String s4 = s1 + s2;  // okay, operator+ found
   }
}

Whether explicitly qualifying a type or via "using", the mapping file is 
consulted to locate the String namespace within the system. The above 
can be further simplified with the use of "automatic deduction of 
primaries" which I describe later in this email.

> Your syntax:
> 
> using SQL.Array;
> class Array;
> 
> Array a;    //ambiguous, which Array
> SQL.Array b;    //refers to item in SQL
> 
> In the second example, there is no way to refer to the local class 
> Array. 

But nothing would be local by default. Every primary (type) requires a 
hosting namespace. Its namespace can be flatten for convince via 
"using", but doesn't have to, if this causes problems.

What I'm trying to show, is that both "import" and "using" are not 
needed, as I believe "import" can be done automatically with the mapping 
file. If there are name clashes with "using", either scope the "using" 
or qualify primaries.

Let me explain the meaning of "primary" type within a namespace. 
Consider this example where a user explicitly qualifies types:

{
   Sql.Integer.Integer si;  // User refers to Integer type (primary)
                            // within Sql.Integer namespace.

   Corba.Integer.Integer si;  // User refers to Integer type (primary)
                              // within Corba.Integer namespace.
}

As you can see, there is some redundancy in qualification above. I 
suggest that a primary type, which is the one that matches the name of 
its enclosing namespace, will be assumed without explicit qualification. 
The above can be written as:

{
   Sql.Integer si;  // okay, refers to primary Integer type in
                    // namespace Sql.Integer

   Corba.Integer si;  // okay, refers to primary Integer type in
                      // namespace Corba.Integer
}

The mapping file will help the compiler to quickly see if a given 
namespace defines a primary and act accordingly.

--

-- 
Slawomir Lisznianski
C2 Language Group Principal (http://c2-lang.org)

-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click

Gmane