Jump to page: 1 2
Thread overview
How to include??
Oct 18, 2007
KAR
Oct 18, 2007
BCS
Oct 18, 2007
KAR
Oct 18, 2007
BCS
Oct 18, 2007
KAR
Oct 18, 2007
Ary Manzana
Oct 18, 2007
BCS
Oct 18, 2007
Bruno Medeiros
Oct 18, 2007
Ary Manzana
Oct 19, 2007
Bill Baxter
Oct 19, 2007
Witold Baryluk
Oct 19, 2007
Ary Manzana
Oct 19, 2007
Bill Baxter
Oct 19, 2007
Bruno Medeiros
Oct 20, 2007
Bruno Medeiros
Oct 20, 2007
Ary Manzana
October 18, 2007
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...
October 18, 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.


October 18, 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).
October 18, 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).


October 18, 2007
BCS Wrote:

> 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).
> 
> 

im getting the ideas now. thanks alot
October 18, 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.
October 18, 2007
Reply to Ary,

> BCS wrote:
> 
>> import is only allowed at module scope, not in a class or function or
>> sutch.
>> 
> IIRC import is allowed in classes.

Oh. it is? Didn't know that

> 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...


October 18, 2007
BCS wrote:
> Reply to Ary,
> 
>> BCS wrote:
>>
>>> import is only allowed at module scope, not in a class or function or
>>> sutch.
>>>
>> IIRC import is allowed in classes.
> 
> Oh. it is? Didn't know that
> 

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#D
October 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,
>>
>>> BCS wrote:
>>>
>>>> import is only allowed at module scope, not in a class or function or
>>>> sutch.
>>>>
>>> IIRC import is allowed in classes.
>>
>> Oh. it is? Didn't know that
>>
> 
> It is "allowed" there (no compiler error) but it has no effect there. It only has effect at module scope.
> 
> 
October 19, 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
« First   ‹ Prev
1 2