Modifing local variables with anonymous delegate?

2013-12-26 Thread Gordon
Hello, A question regarding delegates and local variables: I have the following code, which seems to indicate the delegate function can access "b", but makes a private copy of it, instead of using the "real" b. --- import std.stdio; import std.algorithm; void main() { int[] a = [1,1,1

Re: Modifing local variables with anonymous delegate?

2013-12-26 Thread Timon Gehr
On 12/27/2013 12:23 AM, Gordon wrote: Hello, A question regarding delegates and local variables: I have the following code, which seems to indicate the delegate function can access "b", but makes a private copy of it, instead of using the "real" b. --- ... Map is a lazy range. --- import std.

Re: Modifing local variables with anonymous delegate?

2013-12-26 Thread Adam D. Ruppe
On Thursday, 26 December 2013 at 23:23:02 UTC, Gordon wrote: But the "b" in "main" retains its original value of 42. Try printing the b in main again AFTER printing c. You should see the change. std.algorithm for the most part doesn't actually do any of its calculations until it has to. Thi

Re: Modifing local variables with anonymous delegate?

2013-12-26 Thread Gordon
On Thursday, 26 December 2013 at 23:52:09 UTC, Adam D. Ruppe wrote: On Thursday, 26 December 2013 at 23:23:02 UTC, Gordon wrote: But the "b" in "main" retains its original value of 42. Try printing the b in main again AFTER printing c. You should see the change. std.algorithm for the most p