Splitter quiz / survey

Georg Wrede georg.wrede at iki.fi
Mon Apr 27 00:42:36 PDT 2009


Georg Wrede wrote:
> Brad Roberts wrote:
>> Without looking at the docs, code, or compiling and running a test, 
>> what will
>> this do:
>>
>>     foreach(x, splitter(",a,b,", ","))
>>         writefln("x = %s", a);
>>
>> I'll make it multiple choice:
>>
>> choice 1)
>>   x = a
>>   x = b
>>
>> choice 2)
>>   x =
>>   x = a
>>   x = b
>>
>> choice 3)
>>   x = a
>>   x = b
>>   x =
>>
>> choice 4)
>>   x =
>>   x = a
>>   x = b
>>   x =
> 
> Ehhh, one would /hope/ it's 4.
> 
> Of course, if you're making a fancy library, then the bells-and-whistles 
> version might contain a way to parameterize, so that it can "skip" 
> superfluos commas at the beginning and/or end. But that might be overkill.

Of course, the current behavior is probably related to why you can write

     enum {
         a,
         b,
     }

without a compiler error.

But you're right, in this case it may not be a sane behavior. And 
definitely *not* what the programmer expects.



More information about the Digitalmars-d mailing list