Splitter quiz / survey

Don nospam at nospam.com
Tue Apr 28 00:24:25 PDT 2009


Andrei Alexandrescu 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 =
>>
>> Later,
>> Brad
> 
> Thanks for bringing this to attention, Brad. Splitter does what Perl's 
> split does: 2. This means comma is an item terminator and not an item 
> separator. 

This is the problem, I think. Linguistically, "split" happens at 
seperators (split points), so it should be 4. The argument of utility 
from Perl is reasonable, but with those semantics I think it needs a 
different name - you don't "split" at "terminators". You could get away 
with terminators in a function name like C's "strcol" or "collate", 
where the intuition for how the separation occurs isn't nearly as 
strong, but not for "split".



More information about the Digitalmars-d mailing list