DMD 0.170 release
Reiner Pope
reiner.pope at REMOVE.THIS.gmail.com
Tue Oct 17 15:31:03 PDT 2006
Tom S wrote:
> void each(int[] a, void delegate(int) dg, inout void* ret) {
It would be good to support non-void delegates as well, for things with
predicates, like map, fold, and sort:
int fold(int[] a, int start, void delegate(int, int) dg, inout void* ret)
and
fold(myList, 0) (a, b) { yield a + b; } // Yield returns a value from
the delegate, as opposed to returning from the enclosing function
Note that with some predicates shouldn't be able to control the flow of
code, so I think that last parameter (inout void* ret) should be
optional -- if the last parameter is a delegate, then break and return
can't be used within the delegate.
> for (int i = 0; i < a.length; ++i) {
> dg(a[i]);
> if (ret) return;
> }
> }
>
> each (arr) (int a) {
Of course, this should be type-inferred so you just need to write
each (arr) (a) { ... }
or
arr.each (a) { ... }
Cheers,
Reiner
More information about the Digitalmars-d-announce
mailing list