[OT] foreach(scheme) (Was: Differentiate const flavors using CASE?)

Deewiant deewiant.doesnotlike.spam at gmail.com
Wed Mar 21 23:25:00 PDT 2007


Daniel Keep wrote:
 > In any case, I like the idea of having foreach(scheme), where "scheme"
> could be "forward", "reverse", "depthfirst", "topological", whatever.
> And if D2.0 gets generators as well... well, I can't think of any other
> procedural language that could even come close to touching us :)
> 
> 	-- Daniel
> 
> P.S. One last thought:
> 
> class Heap
> {
>     int opApply(...) { ... dg(v); ... }
>     int opApplyReverse(...) { ... }
>     int opApply_depthfirst(...) { ... }
>     int opApply_sorted(...) { ... }
> 
>     // Wouldn't it be cool if the above could be written as...
> 
>     foreach(...) { foreach( v ; this.backing ) yield v; }
>     foreach(reverse)(...) { ... }
>     foreach(depthfirst)(...) { ... }
>     foreach(sorted)(...) { ... }
> }
> 

That /would/ be cool. I think a syntax like "foreach (delegate) (index, data;
collection)" instead of the current "foreach (index, data;
&delegate(collection))" would be really nice.



More information about the Digitalmars-d mailing list