Differentiate const flavors using CASE?

Reiner Pope reiner at none.com
Thu Mar 22 03:48:07 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Yah :o). Speaking of foreach_reverse, probably it would be wise to lobby 
> Walter to deprecate it in favor of foreach(reverse) (item ; collection) 
> { ... }. The keyword(extra) syntax is definitely becoming a D signature 
> syntax.
> 
> 
> Andrei
I'm surprised no-one has mentioned Tom S's proposal back from DMD 0.170: 
allow trailing delegates to support arbitrary iterating (see 
http://www.digitalmars.com/pnews/read.php?server=news.digitalmars.com&group=digitalmars.D.announce&artnum=4940)

It was met with a very positive reaction back then, but nothing ever 
really came of it.

Basically, it allows iteration styles of any name, as people are 
suggesting again now, but instead of the foreach(iteration_style)(item; 
collection) syntax suggested here, you could just write:

     collection.iteration_style (item) { code; }

So you would get things like:

     collection.random_each (i) { writefln(i); }

Feature-wise, this doesn't add much to what people suggest here, but it 
makes sense when you want to go beyond foreach-style iterators. Also, 
some things are just better expressed without the 'foreach' there to get 
in the way:

     5.times { writefln("Hello World!"); }

Let's face it: you can do more stuff with delegates than can be 
described by saying 'for each element of some set.'

Cheers,

Reiner



More information about the Digitalmars-d mailing list