digitalmars.D.learn - How to include??
- KAR (2/2) Oct 17 2007 Hello all, im a c programmer for years, and recently and recently trying...
- BCS (9/19) Oct 17 2007 import fulfills the same purpose as #include. But rather than have a .h ...
- KAR (3/3) Oct 17 2007 thanks for your quick reply.
- BCS (8/10) Oct 17 2007 I don't understand the question. could you please rephrase it.
- KAR (2/20) Oct 17 2007 im getting the ideas now. thanks alot
- Ary Manzana (2/4) Oct 18 2007 IIRC import is allowed in classes. Also in structs, version, debug, etc.
- BCS (4/12) Oct 18 2007 well the inside of static if, version and debug are technically at the s...
- Bruno Medeiros (6/17) Oct 18 2007 It is "allowed" there (no compiler error) but it has no effect there. It...
- Ary Manzana (17/34) Oct 18 2007 This compiles, runs, and outputs "hola" as expected:
- Bill Baxter (4/23) Oct 18 2007 Hey, then maybe that's a good workaround for no imports in unittests.
- Witold Baryluk (16/21) Oct 18 2007 I also didn't know that import are possible in classes.
- Ary Manzana (8/33) Oct 18 2007 The problem is that in a module, class or struct scope (and the rest
- Bill Baxter (12/20) Oct 18 2007 I just noticed the other day that you can't declare overloaded functions...
- Bruno Medeiros (8/28) Oct 19 2007 Hum, you're right. That's quite odd, I has the distinct impression of
- Bruno Medeiros (18/23) Oct 20 2007 Apparently it's allowed in function/statements scope too, with a workaro...
- Ary Manzana (2/27) Oct 20 2007 Smart :-)
Hello all, im a c programmer for years, and recently and recently trying to switch for better language since my projects becoming biger and bigger, now i need faster language in terms of development but i never fan of c++, D looks promising but starting up can be frustating since not much in tutorial provided. Can somebody tell me of source code filing structure, since ive been use #include and stuff for long, and not familiar with d module and import...
Oct 17 2007
Reply to KAR,Hello all, im a c programmer for years, and recently and recently trying to switch for better language since my projects becoming biger and bigger, now i need faster language in terms of development but i never fan of c++, D looks promising but starting up can be frustating since not much in tutorial provided. Can somebody tell me of source code filing structure, since ive been use #include and stuff for long, and not familiar with d module and import...import fulfills the same purpose as #include. But rather than have a .h file that defines thing and a .c file that implements them, you only have one file that both defines and implements things. The import statement does it all for you. When the compiler finds an import, it does some of the compiling of the imported file, enough that it can get the list of function, classes, structs, enums etc. that are defined. These are added to the list of available symbols much like prototypes in a .h file do. Hopefully that will answer your question. If not, ask some more.
Oct 17 2007
thanks for your quick reply. its a bit clear for me now as i found tutorial on module usage in dsource, however does all import should be declare as a module? btw, fyi im going to experiment D for my search engine (indexer, crawler and search daemon), which if successful will be integrate into our projects and might be free or opensource as well (a bit like lucene but focusing on speeed).
Oct 17 2007
Reply to KAR,however does all import should be declare as a module?I don't understand the question. could you please rephrase it. I'll take a few guesses though: import is only allowed at module scope, not in a class or function or sutch. only a module can be imported, you can't import all modules in a directory (a apckage) with one import, you need to import each module by its self. You can import only a few symbols from a module with selective imports (that's in the docs).
Oct 17 2007
BCS Wrote:Reply to KAR,im getting the ideas now. thanks alothowever does all import should be declare as a module?I don't understand the question. could you please rephrase it. I'll take a few guesses though: import is only allowed at module scope, not in a class or function or sutch. only a module can be imported, you can't import all modules in a directory (a apckage) with one import, you need to import each module by its self. You can import only a few symbols from a module with selective imports (that's in the docs).
Oct 17 2007
BCS wrote:import is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes. Also in structs, version, debug, etc.
Oct 18 2007
Reply to Ary,BCS wrote:Oh. it is? Didn't know thatimport is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes.Also in structs, version, debug, etc.well the inside of static if, version and debug are technically at the same scope as the outside so...
Oct 18 2007
BCS wrote:Reply to Ary,It is "allowed" there (no compiler error) but it has no effect there. It only has effect at module scope. -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#DBCS wrote:Oh. it is? Didn't know thatimport is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes.
Oct 18 2007
This compiles, runs, and outputs "hola" as expected: --- class X { import std.stdio; void foo() { writefln("hola"); } } void main() { (new X()).foo(); } --- Even more, if you move the foo function outside X, it doesn't compile because it can't find "writefln". If I remember correctly from what I've seen in DMD's code, the import loads the imported symbols into the symbol table of the current scope (X, in this case). So... it works. :-) Bruno Medeiros wrote:BCS wrote:Reply to Ary,It is "allowed" there (no compiler error) but it has no effect there. It only has effect at module scope.BCS wrote:Oh. it is? Didn't know thatimport is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes.
Oct 18 2007
Ary Manzana wrote:This compiles, runs, and outputs "hola" as expected: --- class X { import std.stdio; void foo() { writefln("hola"); } } void main() { (new X()).foo(); } --- Even more, if you move the foo function outside X, it doesn't compile because it can't find "writefln". If I remember correctly from what I've seen in DMD's code, the import loads the imported symbols into the symbol table of the current scope (X, in this case). So... it works. :-)Hey, then maybe that's a good workaround for no imports in unittests. Just make a big Test class inside unittest{...} that does all the work. --bb
Oct 18 2007
Dnia Fri, 19 Oct 2007 10:45:27 +0900 Bill Baxter <dnewsgroup billbaxter.com> napisa=B3/a:Hey, then maybe that's a good workaround for no imports in unittests. Just make a big Test class inside unittest{...} that does all the work. =20 --bbI also didn't know that import are possible in classes. unittest { class Test { import std.stdio static test() { ... } } Test.test(); } hackish :) Imports in functions and unittest will be also be helpful. --=20 Witold Baryluk, aleph0
Oct 18 2007
The problem is that in a module, class or struct scope (and the rest where imports are now allowed) you can just put any declaration you want. This is not the case in a function. For example, you can't declare a template inside a function. Humm... And I'm out of examples. Are templates the only declarations not allwed in a function? Because otherwise, I think it would be possible to import inside a function or unittest... Witold Baryluk escribió:Dnia Fri, 19 Oct 2007 10:45:27 +0900 Bill Baxter <dnewsgroup billbaxter.com> napisa³/a:Hey, then maybe that's a good workaround for no imports in unittests. Just make a big Test class inside unittest{...} that does all the work. --bbI also didn't know that import are possible in classes. unittest { class Test { import std.stdio static test() { ... } } Test.test(); } hackish :) Imports in functions and unittest will be also be helpful.
Oct 18 2007
Ary Manzana wrote:The problem is that in a module, class or struct scope (and the rest where imports are now allowed) you can just put any declaration you want. This is not the case in a function. For example, you can't declare a template inside a function. Humm... And I'm out of examples. Are templates the only declarations not allwed in a function? Because otherwise, I think it would be possible to import inside a function or unittest...I just noticed the other day that you can't declare overloaded functions inside a function. eg: void foo() { void blarf(int x) { } void blarf(string x) {} blarf(3); blarf("hi there"); } --bb
Oct 18 2007
Ary Manzana wrote:This compiles, runs, and outputs "hola" as expected: --- class X { import std.stdio; void foo() { writefln("hola"); } } void main() { (new X()).foo(); } --- Even more, if you move the foo function outside X, it doesn't compile because it can't find "writefln". If I remember correctly from what I've seen in DMD's code, the import loads the imported symbols into the symbol table of the current scope (X, in this case). So... it works. :-)Hum, you're right. That's quite odd, I has the distinct impression of trying that before (when looking how Mmrnmhrm functionality should work) and it not working that way. Was there maybe some DMD version that didn't work that way I wonder?... -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#D
Oct 19 2007
Ary Manzana wrote:BCS wrote:Apparently it's allowed in function/statements scope too, with a workaround: template Tpl() { import std.stdio; } void func() { mixin Tpl!(); writefln("Foo"); } void main() { //writefln("Foo"); // writefln not available func(); } Seems it's only disallowed on a syntactic level. -- Bruno Medeiros - MSc in CS/E student http://www.prowiki.org/wiki4d/wiki.cgi?BrunoMedeiros#Dimport is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes. Also in structs, version, debug, etc.
Oct 20 2007
Bruno Medeiros escribió:Ary Manzana wrote:Smart :-)BCS wrote:Apparently it's allowed in function/statements scope too, with a workaround: template Tpl() { import std.stdio; } void func() { mixin Tpl!(); writefln("Foo"); } void main() { //writefln("Foo"); // writefln not available func(); } Seems it's only disallowed on a syntactic level.import is only allowed at module scope, not in a class or function or sutch.IIRC import is allowed in classes. Also in structs, version, debug, etc.
Oct 20 2007