The magic behind foreach (was: Re: Descent 0.5.3 released)

Bill Baxter wbaxter at gmail.com
Sat Jan 24 09:18:12 PST 2009


On Sun, Jan 25, 2009 at 2:06 AM, Ary Borenszweig <ary at esperanto.org.ar> wrote:
> Christopher Wright wrote:
>>
>> Bill Baxter wrote:
>>>
>>> It's not?
>>>
>>> foreach(i;  things) {
>>>      if (i==a) continue;
>>>      if (i==b) break;
>>>      if (i==d) return;
>>>      if (i==c) goto somewhere;
>>> }
>>>
>>> Those are all fairly common things to do from inside the 'dg' call.
>>> The int is how the compiler distinguishes which case got you out of
>>> the dg.
>>>
>>> --bb
>>
>> You didn't read my post carefully.

I could have read it 1000 times and it wouldn't have helped.  It was
not clear exactly when you were talking about the action being taken
or by whom.


>> The use case you would lose is:
>> int opApply (int delegate(something) dg)
>> {
>>   auto result = dg(stuff);
>>   if (result)
>>   {
>>      // This would be impossible if we took a void delegate.
>>      log ("iteration stopped early");
>>      return result;
>>   }
>>   return 0;
>> }
>
> Why would you ever want to do that??

It was pretty clear that he didn't think it a common or particularly
useful pattern.

--bb



More information about the Digitalmars-d mailing list