Re: How do I create a module-local immutable class object?

2011-09-12 Thread Steven Schveighoffer
On Sat, 10 Sep 2011 17:06:44 -0400, Andrej Mitrovic andrej.mitrov...@gmail.com wrote: On 9/10/11, bearophile bearophileh...@lycos.com wrote: Andrej Mitrovic Wrote: Wait a minute, I've just realized private on a class definition has no effect. Why is that? Try to import that class from

Re: How do I create a module-local immutable class object?

2011-09-10 Thread bearophile
Andrej Mitrovic Wrote: Wait a minute, I've just realized private on a class definition has no effect. Why is that? Try to import that class from another module... Bye, bearophile

Re: How do I create a module-local immutable class object?

2011-09-10 Thread bearophile
Try to import that class from another module... I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name itself. Bye, bearophile

Re: How do I create a module-local immutable class object?

2011-09-10 Thread Jonathan M Davis
On Saturday, September 10, 2011 05:20:51 bearophile wrote: Try to import that class from another module... I fear this is a D design mistake/corner case. If you add tags to a class/struct definition it usually gets applied to all its methods, but here it works on the class/struct name

Re: How do I create a module-local immutable class object?

2011-09-10 Thread Andrej Mitrovic
On 9/10/11, bearophile bearophileh...@lycos.com wrote: Andrej Mitrovic Wrote: Wait a minute, I've just realized private on a class definition has no effect. Why is that? Try to import that class from another module... It doesn't stop imports, that's what I'm saying. I can import and

Re: How do I create a module-local immutable class object?

2011-09-10 Thread Andrej Mitrovic
foo\bar.d: module foo.bar; private class Foo {} main.d: import foo.bar : Foo; void main() { auto foo = new Foo(); } This should be a compile error, no?

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Andrej Mitrovic
Ok it seems using const works, so I can use that instead. Still I'm wondering why I can't initialize foo inside a module ctor.

Re: How do I create a module-local immutable class object?

2011-09-09 Thread bearophile
Andrej Mitrovic: I need to have an object which is initialized only once, so I thought I could use immutable for that. But I can't do this: private class Foo {} immutable Foo foo; static this() { foo = new Foo; } void main() {} private class Foo {} immutable Foo foo1; static

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Andrej Mitrovic
On 9/9/11, bearophile bearophileh...@lycos.com wrote: private class Foo {} immutable Foo foo1; static this() { foo1 = new immutable(Foo); } Oh right, that's the syntax. Thanks!

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Jonathan M Davis
On Friday, September 09, 2011 17:37:26 bearophile wrote: Andrej Mitrovic: I need to have an object which is initialized only once, so I thought I could use immutable for that. But I can't do this: private class Foo {} immutable Foo foo; static this() { foo = new Foo;

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Timon Gehr
On 09/09/2011 11:42 PM, Jonathan M Davis wrote: On Friday, September 09, 2011 17:37:26 bearophile wrote: Andrej Mitrovic: I need to have an object which is initialized only once, so I thought I could use immutable for that. But I can't do this: private class Foo {} immutable Foo foo; static

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Andrej Mitrovic
So much for that idea, immutable breaks property functions. Take a look: class Foo { this() { value = true; } @property bool value() { return true; } @property void value(bool value) { } } void main() { auto foo1 = new Foo; auto val1 = foo1.value; auto

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Andrej Mitrovic
For crying out loud, shared fails too: class Foo { shared this() { value = true; } @property bool value() { return true; } @property void value(bool value) { } } void main() { auto foo1 = new Foo; auto val1 = foo1.value; // fail }

Re: How do I create a module-local immutable class object?

2011-09-09 Thread David Nadlinger
On 9/9/11 11:45 PM, Andrej Mitrovic wrote: So much for that idea, immutable breaks property functions. Take a look: class Foo { this() { value = true; } @property bool value() { return true; } @property void value(bool value) { } } void main() { auto

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Jonathan M Davis
On Friday, September 09, 2011 23:44:10 Timon Gehr wrote: On 09/09/2011 11:42 PM, Jonathan M Davis wrote: On Friday, September 09, 2011 17:37:26 bearophile wrote: Andrej Mitrovic: I need to have an object which is initialized only once, so I thought I could use immutable for that. But I

Re: How do I create a module-local immutable class object?

2011-09-09 Thread Andrej Mitrovic
Ok so this is much more involved than I thought. I need to re-read parts of TDPL again. Sorry for the excessive noise. :p