Re: Pure delegate not quite pure?

2015-07-01 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 9:29 PM, Tofu Ninja wrote: On Wednesday, 1 July 2015 at 00:13:36 UTC, Jesse Phillips wrote: On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature?

Re: Pure delegate not quite pure?

2015-07-01 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 12:34:35 UTC, Steven Schveighoffer wrote: immutable is probably incorrect without a cast, since immutable cannot be applied implicitly to non-immutable data, and if the data is all immutable already, no sense in tagging it immutable. I really see use in allowing

Re: Pure delegate not quite pure?

2015-06-30 Thread Jesse Phillips via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Wednesday, 1 July 2015 at 00:13:36 UTC, Jesse Phillips wrote: On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = ()

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:23:40 UTC, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Tuesday, 30 June 2015 at 22:05:43 UTC, Steven Schveighoffer wrote: Have you tried placing const on the function signature? i.e.: pure int delegate() const d = () const {... That's how you'd do it (I think, didn't test) if the delegate context pointer was a class/struct. -Steve Nah,

Re: Pure delegate not quite pure?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 5:44 PM, Tofu Ninja wrote: On Tuesday, 30 June 2015 at 21:31:05 UTC, Steven Schveighoffer wrote: On 6/30/15 5:23 PM, Tofu Ninja wrote: On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const? const x = 4 ;) But even if

Re: Pure delegate not quite pure?

2015-06-30 Thread Tofu Ninja via Digitalmars-d-learn
On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const?

Re: Pure delegate not quite pure?

2015-06-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/30/15 5:23 PM, Tofu Ninja wrote: On Sunday, 28 June 2015 at 10:19:05 UTC, anonymous wrote: [...] Is there any way to annotate the context as const? const x = 4 ;) But even if you could annotate just the *reference* as const, it doesn't stop foo from changing it as you did in the

Re: Pure delegate not quite pure?

2015-06-28 Thread anonymous via Digitalmars-d-learn
On Sunday, 28 June 2015 at 09:19:16 UTC, Tofu Ninja wrote: module main; import std.stdio; void main(string[] args) { auto d = foo(); writeln(d()); // prints 25 } auto foo() { int x = 4; pure int delegate() d = delegate() { return x*x;

Pure delegate not quite pure?

2015-06-28 Thread Tofu Ninja via Digitalmars-d-learn
module main; import std.stdio; void main(string[] args) { auto d = foo(); writeln(d()); // prints 25 } auto foo() { int x = 4; pure int delegate() d = delegate() { return x*x; }; writeln(d()); // prints 16 x = 5;

Re: Pure delegate not quite pure?

2015-06-28 Thread via Digitalmars-d-learn
On Sunday, 28 June 2015 at 09:19:16 UTC, Tofu Ninja wrote: module main; import std.stdio; void main(string[] args) { auto d = foo(); writeln(d()); // prints 25 } auto foo() { int x = 4; pure int delegate() d = delegate() { return x*x;