splitting numbers from a test file

Craig Dillabaugh cdillaba at cg.scs.carleton.ca
Tue Sep 18 21:56:23 PDT 2012


On Wednesday, 19 September 2012 at 04:03:44 UTC, Jonathan M Davis
wrote:
> On Wednesday, September 19, 2012 05:36:36 Craig Dillabaugh 
> wrote:
>> Thanks, a few others have pointed that out to me too.  But as 
>> a D
>> newbie how would I have any clue what splitter returns since 
>> the
>> return type is auto?
>
> The documentation says that it returns a range. Presumably 
> then, the problem
> is that you're not familiar with ranges, and that needs to be 
> handled better.
> We really need a proper article/tutorial on the main site which 
> explains them,
> and we don't. But I don't know what we'd do differently in the 
> documentation
> for functions in general. Ranges are a concept that are used 
> quite heavily in
> Phobos, and it wouldn't make sense to try and explain them for 
> every function
> that uses them.
From:
http://dlang.org/phobos/std_array.html#splitter

The documentation (copied and pasted) for splitter reads:

auto splitter(C)(C[] s);
Splits a string by whitespace.

Example:
auto a = " a     bcd   ef gh ";
assert(equal(splitter(a), ["", "a", "bcd", "ef", "gh"][]));

I have this awful feeling that I am missing something blatantly
obvious here, and that by posting this reply I am leaving a
permanent testament to my stupidity on the internet, but I really
want to understand this ...

I just want to figure out how you can explicitly say "the
documentation says it returns a range" based on that!  Is is
simply because you recognize the range from the assert statement
in the example?

I am sure the Phobos developers have better things to do then
writing documentation that coddles newbies, but could the
documentation not say:

auto splitter(C)(C[] s);
Splits a string by whitespace. Returns an InputRange of all
substrings.

Or something to that affect.

Thanks again for your time.

clip ....



More information about the Digitalmars-d-learn mailing list