Re: this() immutable

2013-10-23 Thread H. S. Teoh
On Wed, Oct 23, 2013 at 09:47:00PM +0200, Daniel Davidson wrote: > On Wednesday, 16 October 2013 at 21:11:19 UTC, H. S. Teoh wrote: [...] > >Hmm. I just did a quick-n-dirty change to Phobos, and it seems to > >make chain() usable with pure code. I'm not sure why the compiler > >didn't infer pure fo

Re: this() immutable

2013-10-23 Thread Daniel Davidson
On Wednesday, 16 October 2013 at 21:11:19 UTC, H. S. Teoh wrote: On Wed, Oct 16, 2013 at 10:09:50PM +0200, Daniel Davidson wrote: [...] I reported my issue with the `chain` function to this NG and tried to start annotating items used by chain with pure to see how far the thread led. Honestly it

Re: this() immutable

2013-10-16 Thread H. S. Teoh
On Wed, Oct 16, 2013 at 02:10:02PM -0700, H. S. Teoh wrote: > On Wed, Oct 16, 2013 at 10:09:50PM +0200, Daniel Davidson wrote: > [...] > > I reported my issue with the `chain` function to this NG and tried > > to start annotating items used by chain with pure to see how far the > > thread led. Hone

Re: this() immutable

2013-10-16 Thread Jonathan M Davis
On Wednesday, October 16, 2013 14:10:02 H. S. Teoh wrote: > This is just a hack, of course. The compiler *should* be able to > correctly infer that the ctor is pure. So the real fix is to find out > why the compiler isn't doing that. Because it sucks at attribute inference. The inference that it d

Re: this() immutable

2013-10-16 Thread H. S. Teoh
On Wed, Oct 16, 2013 at 10:09:50PM +0200, Daniel Davidson wrote: [...] > I reported my issue with the `chain` function to this NG and tried > to start annotating items used by chain with pure to see how far the > thread led. Honestly it was quickly clear that it led too far for me > to follow it an

Re: this() immutable

2013-10-16 Thread Dicebot
On Wednesday, 16 October 2013 at 20:09:51 UTC, Daniel Davidson wrote: You and dicebot surely disagree on this practice as he sees no real reason to ever circumvent the type system. There are some cases were you have no other options because of language design limitations but it is something th

Re: this() immutable

2013-10-16 Thread Daniel Davidson
object normally (i.e. mutable), and then later "freeze" it to immutable via a simple cast or so? In std.exception there is assumeUnique. It's basically just a cast, but might be good enough for you. Is there any other recourse here? Why does making `this(...) immutable` f

Re: this() immutable

2013-10-16 Thread Simen Kjaeraas
uot; it to immutable via a simple cast or so? In std.exception there is assumeUnique. It's basically just a cast, but might be good enough for you. Is there any other recourse here? Why does making `this(...) immutable` fix things below? Shouldn't that immutable designation mean no mem

Re: this() immutable

2013-10-16 Thread Daniel Davidson
.exception there is assumeUnique. It's basically just a cast, but might be good enough for you. Is there any other recourse here? Why does making `this(...) immutable` fix things below? Shouldn't that immutable designation mean no members of this will be modified? But that is t

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Gary Willoughby
On Wednesday, 9 October 2013 at 16:02:43 UTC, Daniel Davidson wrote: Maybe this will help explain it: void main() { pragma(msg, typeof(Bar.name)); pragma(msg, typeof(Foo.change)); } will print: immutable(char[][]) void(string[] name) The latter is really: void(immutable(char)[] name) The

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Daniel Davidson
On Wednesday, 9 October 2013 at 15:33:23 UTC, Ali Çehreli wrote: That string is independent from the argument (i.e. Bar.name). They initially share the same characters. Either of those strings can leave this sharing at will, and that is exactly what name="tess" does. 'name' now refers to dif

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Daniel Davidson
On Wednesday, 9 October 2013 at 15:46:29 UTC, Gary Willoughby wrote: So why does this give me an error i expect: import std.stdio; class Foo { public void change(string[] name) { name[0] = "tess";

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Dicebot
D does stripping of qualifiers from top level when creating a copy which allows to pass immutable stuff as mutable parameter by value. Adding any single level of immutable indirection will make this impossible and result in compile-time error.

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Gary Willoughby
On Wednesday, 9 October 2013 at 15:33:23 UTC, Ali Çehreli wrote: On 10/09/2013 08:26 AM, Gary Willoughby wrote: Can someone explain why i can change Bar's immutable name member please? import std.stdio; class Foo { public void change(string name) { name

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Orvid King
On Wednesday, 9 October 2013 at 15:26:35 UTC, Gary Willoughby wrote: Can someone explain why i can change Bar's immutable name member please? import std.stdio; class Foo { public void change(string name) { name = "

Re: Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Ali Çehreli
On 10/09/2013 08:26 AM, Gary Willoughby wrote: Can someone explain why i can change Bar's immutable name member please? import std.stdio; class Foo { public void change(string name) { name = "tess"; writeln(name); } }

Can someone explain why i can change this immutable variable please?

2013-10-09 Thread Gary Willoughby
Can someone explain why i can change Bar's immutable name member please? import std.stdio; class Foo { public void change(string name) { name = "tess"; writeln(name); }

Re: this() immutable

2013-06-13 Thread Stephan Schiffels
On Thursday, 13 June 2013 at 12:29:57 UTC, Simen Kjaeraas wrote: On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels wrote: For example, is there a way of instantiating an object normally (i.e. mutable), and then later "freeze" it to immutable via a simple cast or so? In std.exception th

Re: this() immutable

2013-06-13 Thread Simen Kjaeraas
On Thu, 13 Jun 2013 14:17:22 +0200, Stephan Schiffels wrote: For example, is there a way of instantiating an object normally (i.e. mutable), and then later "freeze" it to immutable via a simple cast or so? In std.exception there is assumeUnique. It's basically just a cast, but might be g

this() immutable

2013-06-13 Thread Stephan Schiffels
Hi, I have some problems with adopting my code to a breaking change introduced in version 2.063. Apparently, now it's not anymore possible to instantiate an immutable object via: auto object = new immutable(SomeClass)(contructor_args...); without also defining either this(constructor_args..