digitalmars.D - DMD range support?
- Sergey Gromov (6/6) Jan 10 2009 DMD supports ranges in foreach for more than a month, but I still cannot
- Jarrett Billingsley (3/9) Jan 10 2009 Maybe it just means the ranges in std.range got an opApply, or some
- Sergey Gromov (30/42) Jan 10 2009 No, the following works:
- Steven Schveighoffer (3/32) Jan 12 2009 I'd really like to know the code generation -- A delegate probably isn't...
- Sergey Gromov (41/61) Jan 12 2009 non-optimized asm:
- Andrei Alexandrescu (3/10) Jan 10 2009 Percolating!
- Sergey Gromov (2/12) Jan 10 2009 What do you mean? It's in release notes for DMD 2.021.
- Andrei Alexandrescu (3/16) Jan 10 2009 I mean the related overhaul of std.algorithm is in the works.
DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.html
Jan 10 2009
On Sat, Jan 10, 2009 at 12:36 PM, Sergey Gromov <snake.scaly gmail.com> wrote:DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlMaybe it just means the ranges in std.range got an opApply, or some kind of special treatment by the compiler?
Jan 10 2009
Sat, 10 Jan 2009 13:53:44 -0500, Jarrett Billingsley wrote:On Sat, Jan 10, 2009 at 12:36 PM, Sergey Gromov <snake.scaly gmail.com> wrote:No, the following works: struct Generator(int start, int step, int end) { private int head_ = start; int head() { return head_; } void next() { head_ += step; } bool empty() { return head_ > end; } } import std.stdio; void main() { Generator!(2, 7, 50) gen; foreach (i; gen) writefln(i); } so at least the test method is empty(), not done(). That's a relief. OTOH it does not work if the head is an actual field: struct Generator(int start, int step, int end) { int head = start; void next() { head += step; } bool empty() { return head > end; } } If you use it with foreach (i; gen) you get Error: cannot infer type for i and for foreach (int i; gen): Error: no property 'opApply' for type 'Generator!(2,7,50)' Error: function expected before (), not 1 of type intDMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlMaybe it just means the ranges in std.range got an opApply, or some kind of special treatment by the compiler?
Jan 10 2009
"Sergey Gromov" wroteSat, 10 Jan 2009 13:53:44 -0500, Jarrett Billingsley wrote:I'd really like to know the code generation -- A delegate probably isn't generated anymore? I agree more documentation is sorely needed in the spec.On Sat, Jan 10, 2009 at 12:36 PM, Sergey Gromov <snake.scaly gmail.com> wrote:No, the following works: struct Generator(int start, int step, int end) { private int head_ = start; int head() { return head_; } void next() { head_ += step; } bool empty() { return head_ > end; } } import std.stdio; void main() { Generator!(2, 7, 50) gen; foreach (i; gen) writefln(i); }DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlMaybe it just means the ranges in std.range got an opApply, or some kind of special treatment by the compiler?
Jan 12 2009
Mon, 12 Jan 2009 11:43:11 -0500, Steven Schveighoffer wrote:"Sergey Gromov" wrotenon-optimized asm: __Dmain comdat assume CS:__Dmain L0: enter 4,0 mov EAX,_D4test24__T9GeneratorVi2Vi7Vi50Z9Generator6__initZ mov -4[EBP],EAX mov -4[EBP],EAX LF: lea EAX,-4[EBP] call near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator5emptyMFZb xor AL,1 je L32 lea EAX,-4[EBP] call near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator4headMFZi call near ptr _D3std5stdio15__T8writeflnTiZ8writeflnFiZv lea EAX,-4[EBP] call near ptr _D4test24__T9GeneratorVi2Vi7Vi50Z9Generator4nextMFZv jmp short LF L32: xor EAX,EAX leave ret __Dmain ends optimized asm (-O -release -inline): __Dmain comdat assume CS:__Dmain L0: push EAX mov EAX,_D4test24__T9GeneratorVi2Vi7Vi50Z9Generator6__initZ cmp EAX,032h mov [ESP],EAX jg L25 LE: push [ESP] mov EAX,0Ah call near ptr _D3std5stdio15__T6writefTiTaZ6writefFiaZv add [ESP],7 cmp [ESP],032h jle LE L25: pop ECX xor EAX,EAX ret __Dmain ends *Pretty* nice.struct Generator(int start, int step, int end) { private int head_ = start; int head() { return head_; } void next() { head_ += step; } bool empty() { return head_ > end; } } import std.stdio; void main() { Generator!(2, 7, 50) gen; foreach (i; gen) writefln(i); }I'd really like to know the code generation -- A delegate probably isn't generated anymore? I agree more documentation is sorely needed in the spec.
Jan 12 2009
Sergey Gromov wrote:DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlPercolating! Andrei
Jan 10 2009
Sat, 10 Jan 2009 12:15:22 -0800, Andrei Alexandrescu wrote:Sergey Gromov wrote:What do you mean? It's in release notes for DMD 2.021.DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlPercolating!
Jan 10 2009
Sergey Gromov wrote:Sat, 10 Jan 2009 12:15:22 -0800, Andrei Alexandrescu wrote:I mean the related overhaul of std.algorithm is in the works. AndreiSergey Gromov wrote:What do you mean? It's in release notes for DMD 2.021.DMD supports ranges in foreach for more than a month, but I still cannot find any docs or at least examples of the range syntax. Lots of syntaxes were discussed and it's absolutely not obvious which of them actually got into the compiler. Is this page still relevant? http://ssli.ee.washington.edu/~aalexand/d/tmp/std_range.htmlPercolating!
Jan 10 2009