Modifing local variables with anonymous delegate?
Gordon
me at home.com
Thu Dec 26 16:33:44 PST 2013
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 part doesn't actually do any of its
> calculations until it has to. This allows it to save speed
> skipping work it doesn't need, and make it possible to map
> infinite series and stuff like that.
>
> So the line c = map....; just prepares the calculation, it
> doesn't actually run the function. The writeln(c) forces
> evaluation. You can also force evaluation immediately by
> calling .array on the thing, which calculates it and puts the
> result in a new array.
Thanks!
More information about the Digitalmars-d
mailing list