Re: Delegates: Print 0..9

2016-12-02 Thread Timon Gehr via Digitalmars-d-learn
On 01.12.2016 21:12, Ali Çehreli wrote: This is a common issue with D and some other languages (as I had learned during a Dart language presentation, of which Dart does not suffer from). All those delegates do close on the same loop variable. You need to produce copies of the variable. This

Re: Delegates: Print 0..9

2016-12-01 Thread unDEFER via Digitalmars-d-learn
On Thursday, 1 December 2016 at 20:12:15 UTC, Ali Çehreli wrote: First, the scary syntax that produces a lambda from an int: ... Better: ... All methods.. Thank you!

Re: Delegates: Print 0..9

2016-12-01 Thread Ali Çehreli via Digitalmars-d-learn
On 12/01/2016 11:28 AM, unDEFER wrote: > Hello! > Simple using of delegates: > > === > #!/usr/bin/rdmd > import std.stdio; > > void main() > { > void delegate() functions[]; > > foreach (i; 0..10) > { > void print() > { > writefln("%s", i); >

Re: Delegates: Print 0..9

2016-12-01 Thread unDEFER via Digitalmars-d-learn
Yes, I have found: = #!/usr/bin/rdmd import std.stdio; void main() { void delegate() functions[]; foreach (i; 0..10) { auto get_print(int i) { void print() { writefln("%s", i); }

Delegates: Print 0..9

2016-12-01 Thread unDEFER via Digitalmars-d-learn
Hello! Simple using of delegates: === #!/usr/bin/rdmd import std.stdio; void main() { void delegate() functions[]; foreach (i; 0..10) { void print() { writefln("%s", i); } functions ~= } foreach (i; 0..10) {