Import proposals (Discuss)
Jari-Matti Mäkelä
jmjmak at utu.fi.invalid
Tue Jul 11 13:31:14 PDT 2006
Regan Heath wrote:
> 1. starting with hello world, eg.
>
> --[helloworld.d]--
> import std.stdio;
> void main()
> {
> writefln("Hello World");
> }
>
> 2. Moving on to import his own module eg.
>
> --[mymod.d]--
> void sayHello() { writefln("Hello World"); }
>
> --[helloworld.d]--
> import std.stdio,mymod;
> void main()
> {
> sayHello();
> }
>
> which will all work fine, no problems.
>
> 3. It's when he starts to think.. "I just need writefln why not code it
> like this" ..
>
> --[mymod.d]--
> void sayHello() { writefln("Hello World"); }
>
> --[helloworld.d]--
> import std.stdio.writefln,mymod;
> void main()
> {
> sayHello();
> }
>
> that he'll get an error.
Of course he gets an error. How are you supposed to compile these
modules separately (ie. dmd -c mymod.d). It should be:
[mymod.d]
import std.stdio.writefln;
void sayHello() { writefln("Hello World"); }
[helloworld.d]
import mymod;
// or even: import mymod.sayHello;
void main()
{
sayHello();
}
If you think of mymod.d as a library, how can it depend on an import
statement on a "client" module that is not possibly even implemented yet?
--
Jari-Matti
More information about the Digitalmars-d
mailing list