www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Name of files causes error. Why?

reply "Xan" <xancorreu gmail.com> writes:
Hi,

With helloworld program named with score or underscore, I receive 
the following __annoying__ error:

$ gdmd-4.6 hola-temp.d
hola-temp.d: Error: module hola-temp has non-identifier 
characters in filename, use module declaration instead

Why?
Can someone fix it. It's really annoying

Thanks in advance,
Xan.
Apr 11 2012
next sibling parent Andrej Mitrovic <andrej.mitrovich gmail.com> writes:
On 4/11/12, Xan <xancorreu gmail.com> wrote:
 With helloworld program named with score or underscore, I receive
 the following __annoying__ error:
Underscores should work fine (and they do for me). Scores (or dashes) can't work because an indentifier with a dash is not a valid identifier, so a module declaration can't have dashes, and hence d files can't have them either.
Apr 11 2012
prev sibling next sibling parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Wed, 11 Apr 2012 15:33:56 -0400, Xan <xancorreu gmail.com> wrote:

 Hi,

 With helloworld program named with score or underscore, I receive the  
 following __annoying__ error:

 $ gdmd-4.6 hola-temp.d
 hola-temp.d: Error: module hola-temp has non-identifier characters in  
 filename, use module declaration instead

 Why?
 Can someone fix it. It's really annoying

 Thanks in advance,
 Xan.
All d module files (i.e. d source files) must be a valid identifier. See this document for what an identifier can contain: http://dlang.org/lex.html#Identifier Now, you *can* possibly name the module differently using a module statement, but this is highly discouraged. If you do this, the only way another module can import your differently-named module is if you pass the file on the command line. -Steve
Apr 11 2012
parent reply "Xan" <xancorreu gmail.com> writes:
On Wednesday, 11 April 2012 at 19:50:18 UTC, Steven Schveighoffer 
wrote:
 On Wed, 11 Apr 2012 15:33:56 -0400, Xan <xancorreu gmail.com> 
 wrote:

 Hi,

 With helloworld program named with score or underscore, I 
 receive the following __annoying__ error:

 $ gdmd-4.6 hola-temp.d
 hola-temp.d: Error: module hola-temp has non-identifier 
 characters in filename, use module declaration instead

 Why?
 Can someone fix it. It's really annoying

 Thanks in advance,
 Xan.
All d module files (i.e. d source files) must be a valid identifier. See this document for what an identifier can contain: http://dlang.org/lex.html#Identifier Now, you *can* possibly name the module differently using a module statement, but this is highly discouraged. If you do this, the only way another module can import your differently-named module is if you pass the file on the command line. -Steve
But it's a messy limitation. Why we should have it? For C++ compatibilities? Thanks,
Apr 12 2012
next sibling parent reply Manfred Nowak <svv1999 hotmail.com> writes:
Xan wrote:

 But it's a messy limitation.
On the contrary: it requires work to implement limitations. Therefore limitations are implemented only to shield users from mess. Not having descovered any benefit of a limitation might point to insufficient empirical knowledge. -manfred
Apr 12 2012
parent bearophile <bearophileHUGS lycos.com> writes:
Manfred Nowak:

 On the contrary: it requires work to implement limitations. Therefore 
 limitations are implemented only to shield users from mess.
Also, removing limitations from a language is usually FAR simpler than introducing them later :-) Bye, bearophile
Apr 12 2012
prev sibling next sibling parent "Steven Schveighoffer" <schveiguy yahoo.com> writes:
On Thu, 12 Apr 2012 08:30:50 -0400, Xan <xancorreu gmail.com> wrote:

 On Wednesday, 11 April 2012 at 19:50:18 UTC, Steven Schveighoffer wrote:
 Now, you *can* possibly name the module differently using a module  
 statement, but this is highly discouraged.  If you do this, the only  
 way another module can import your differently-named module is if you  
 pass the file on the command line.
But it's a messy limitation. Why we should have it? For C++ compatibilities?
No. C++ has no requirements for file names. But C++ also doesn't have a module system. There are many benefits we get from having an actual module system. For instance, D doesn't need namespaces. The requirement is pretty straightforward -- name your module files after the modules they contain. It works pretty well in many module-oriented -Steve
Apr 12 2012
prev sibling parent "Jonathan M Davis" <jmdavisProg gmx.com> writes:
On Thursday, April 12, 2012 14:30:50 Xan wrote:
 But it's a messy limitation. Why we should have it? For C++
 compatibilities?
Messy? How so? You can't put any characters in a module name which aren't valid identifiers. So what? Just name your module differently. Is your complaint that you can't just rename your cpp-file.cpp to cpp-file.d, make a few tweaks to its contents, and then have it compile as D? If that's the case, the file name is the least of your concerns. And I don't know why else you'd care about any "compatability" with C++ due to file names. How D interacts with C/C++ has nothing to do with the file names of either. Module names can end up being used inside code to fully qualify symbol names. e.g. std.algorithm.sort(arr); If you could put characters in a module name which weren't valid in an identifier, this would cause serious issues for the lexer and parser. std.algo-rithm.sort(arr); So, it's a very reasonable restriction that a module name be required to be a valid identifier. And this is not unusal among programming languages with module systems. C/C++ doesn't have such restrictions, because they had the misfortune to choose the whole #include mess. Their choice is p probably due - at least in part - to computing restrictions at the time which would have made putting all of the symbols in memory too expensive, so as bad as it is, they probably didn't have much choice, but it still has horrible problems - some of which are listed here: http://www.drdobbs.com/blogs/cpp/228701711 D's modules are _far_ better, even if with their restrictions on file names. - Jonathan M Davis
Apr 12 2012
prev sibling parent reply "Jesse Phillips" <jessekphillips+D gmail.com> writes:
On Wednesday, 11 April 2012 at 19:33:58 UTC, Xan wrote:
 Hi,

 With helloworld program named with score or underscore, I 
 receive the following __annoying__ error:

 $ gdmd-4.6 hola-temp.d
 hola-temp.d: Error: module hola-temp has non-identifier 
 characters in filename, use module declaration instead

 Why?
 Can someone fix it. It's really annoying

 Thanks in advance,
 Xan.
Module names are used for import statements: import mymodule; As this is D code, it must have a valid identifier so that it parses import my-module; This could probably be special cased, but you can use these names in code auto a = my-module.foo(); Are you subtracting 'my' from 'module.foo()?' You can name you files whatever you want. Just include your module name at the top (recommended anyway) module my_module; In this case, if you module file is named my-module, then rdmd and other build tools that use your import information will be unable to locate my_module.d because that file does not exist.
Apr 12 2012
parent "Xan" <xancorreu gmail.com> writes:
On Friday, 13 April 2012 at 04:16:52 UTC, Jesse Phillips wrote:
 On Wednesday, 11 April 2012 at 19:33:58 UTC, Xan wrote:
 Hi,

 With helloworld program named with score or underscore, I 
 receive the following __annoying__ error:

 $ gdmd-4.6 hola-temp.d
 hola-temp.d: Error: module hola-temp has non-identifier 
 characters in filename, use module declaration instead

 Why?
 Can someone fix it. It's really annoying

 Thanks in advance,
 Xan.
Module names are used for import statements: import mymodule; As this is D code, it must have a valid identifier so that it parses import my-module; This could probably be special cased, but you can use these names in code auto a = my-module.foo(); Are you subtracting 'my' from 'module.foo()?' You can name you files whatever you want. Just include your module name at the top (recommended anyway) module my_module; In this case, if you module file is named my-module, then rdmd and other build tools that use your import information will be unable to locate my_module.d because that file does not exist.
Thanks, Jesse, for your deep explanation. Now I understant: it's for not confusing with minus Thanks, Xan.
Apr 13 2012