www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - package.d imports

reply "Lemonfiend" <lemon fie.nd> writes:
The following behavior seems odd to me. Could anyone explain why 
it works as it does? (Does package.d have a page on dlang.org?)

--- main.d
module main;

void main()
{
	test1();
	test2();
}

void test1()
{
	import pack;

	// works
	foo();

	// works, did not expect it to
	pack.foo();

	// does not work: Error: undefined identifier 'sub'
	//pack.sub.foo();
}

void test2()
{
	import pack.sub;

	// works
	foo();

	// works, even more unexpectedly
	pack.foo();

	// works
	pack.sub.foo();
}

--- package/pack.d
module pack;

public import pack.sub;

--- package/sub.d
module pack.sub;

void foo()
{
	import std.stdio;
	writeln("hello");	
}
Jan 16 2014
next sibling parent "Lemonfiend" <lemon fie.nd> writes:
Sorry, that's
--- pack/package.d
and
--- pack/sub.d
Jan 16 2014
prev sibling parent reply "Colden Cullen" <ColdenCullen gmail.com> writes:
On Thursday, 16 January 2014 at 15:46:01 UTC, Lemonfiend wrote:
 The following behavior seems odd to me. Could anyone explain 
 why it works as it does? (Does package.d have a page on 
 dlang.org?)

 --- main.d
 module main;

 void main()
 {
 	test1();
 	test2();
 }

 void test1()
 {
 	import pack;

 	// works
 	foo();

 	// works, did not expect it to
 	pack.foo();

 	// does not work: Error: undefined identifier 'sub'
 	//pack.sub.foo();
 }

 void test2()
 {
 	import pack.sub;

 	// works
 	foo();

 	// works, even more unexpectedly
 	pack.foo();

 	// works
 	pack.sub.foo();
 }

 --- package/pack.d
 module pack;

 public import pack.sub;

 --- package/sub.d
 module pack.sub;

 void foo()
 {
 	import std.stdio;
 	writeln("hello");	
 }
I think this is what you are looking for: http://dlang.org/changelog.html#import_package
Jan 17 2014
parent reply "Lemonfiend" <lemon fie.nd> writes:
 I think this is what you are looking for: 
 http://dlang.org/changelog.html#import_package
What an odd place to put it.. Too bad, it doesn't mention anything about calling the functions like in my example, and why some do/don't work. I'd hoped for more.
Jan 17 2014
parent Leandro Motta Barros <lmb stackedboxes.org> writes:
Hi!

I made similar questions here a month ago, but also couldn't get definitive
answers. I just sent a message about this to the main D forum. Let's see if
we have better luck there :-)

Cheers,

LMB



On Fri, Jan 17, 2014 at 5:39 PM, Lemonfiend <lemon fie.nd> wrote:

 I think this is what you are looking for: http://dlang.org/changelog.
 html#import_package
What an odd place to put it.. Too bad, it doesn't mention anything about calling the functions like in my example, and why some do/don't work. I'd hoped for more.
Jan 18 2014