Import proposals (Ideas)

Regan Heath regan at netwin.co.nz
Sun Jul 9 16:31:43 PDT 2006


This idea is broken into parts, other people might like to reference these  
parts in discussion or in their own ideas i.e. "using Regan's Part-A and  
.." etc.

--

Part-A:
import this.is.the.lib;

This imports all symbols from this.is.the.lib into the current scope. No  
changes to current import behaviour here. I have an alternate idea, not  
sure what people might think of this as it breaks all/most existing code  
but..

--

Alt-A:
import this.is.the.lib;
import this.is.the.lib as .;

So, import defaults to FQN and 'as' (properly introduced in Part-B below)  
must be used to import into the current scope (which is named '.')

--

Part-B:
import this.is.the.lib as x;

This imports all symbols from this.is.the.lib into named scope 'x'

--

Part-C:
import this.is.the.lib.copyFile,saveFile,deleteFile;

This imports the named symbols copyFile, saveFile, and deleteFile from  
this.is.the.lib into the current scope. The lib name is mentioned only  
once and therefore only one lib may be present in the import statement.

This idea may conflict with the current statement:
   import this.is.a.lib,this.is.another.lib;

which I've notice people use (but don't use personally).

The compiler can tell these apart by realising that the first part of the  
import denotes a symbol in a module, as opposed to a module itself. Then  
we have to ask ourselves, what if a module is later created by the name  
this.is.the.lib.copyFile .. I don't know, this is perhaps the most  
contrary part of my idea.

The advantage I see to this is that it only imports the symbols you want  
and to add a symbol you just add "," and the symbol name to the same line.  
So, it keeps the symbols from the same module together on one  
line/statement (which seems to me to be what people dislike about alias?)  
and does not involve needlessly repeating the module name.

--

Alt-C:
import this.is.the.lib.copyFile,saveFile,deleteFile;

This would import as FQN and not into the current scope (without use of  
'as .' as shown in Part-D below).

--

Part-D:
import this.is.the.lib.copyFile,saveFile,deleteFile as x;

This imports the named symbols copyFile, saveFile, and deleteFile from  
this.is.the.lib into the named scope 'x'.

--

Part-E: (extension of Part-B)
import this.is.the.lib as this.is.the.lib;

This imports all the symbols from this.is.the.lib into the named scope  
'this.is.the.lib' .. or in other words, this is an FQN import. My  
impression is that most people would rather not have FQN as the default,  
but do want it to be possible. My impression is that applying 'static' to  
import to achieve FQN import is disliked (I certainly dislike it). This  
seems a good compromise.

--

The complete idea/system combines all these parts. The "Alt" parts break  
existing code, the others shouldn't. The reasons for not simply using  
alias have been well hashed out already, from what I can see it's a  
maintenance and aesthetic request, as opposed to a truly functional  
improvement but that's reason enough for me to desire a change.

Regan



More information about the Digitalmars-d mailing list