Custom Blocks
Nick Sabalausky
a at a.a
Tue Aug 10 12:06:03 PDT 2010
"Chris Williams" <aahz at seanet.com> wrote in message
news:i3s1a9$2vbc$1 at digitalmars.com...
>
> int main() {
> for (uint i = 0; i < 5; i++) {
> doOnce() {
> return 42;
> }
> ...do stuff
> }
>
> return 0;
> }
>
> Having a return value sitting in the middle of what looks like a local
> block is a bit ugly. It seems like main() will end at "return 42". For
> creating something that operates like a code block, we would never
> want a return.
>
That's a very good point.
> That brings us to the second problem. Our last parameter for a custom
> block is always "void delegate()" and our return is always void.
Currently, all blocks are void, but I'm not sure that limitation should be
preserved for custom blocks. Example:
auto result = collection.reduce(a, b) { return a + b; };
More information about the Digitalmars-d
mailing list