Trying to compile sample from The D Programming Language book.

Jonathan M Davis jmdavisProg at gmx.com
Sun Apr 3 00:44:15 PDT 2011


On 2011-04-03 00:10, Junior wrote:
> Hello, I am completely stuck on this error, any help would be
> appreciated... google was not helpful (too many useless matches for "D
> <error>").
> 
> I am trying to compile this:
> 
> import std.string, std.algorithm, std.conv, std.ctype, std.regex,
> std.range, std.stdio;
> // blah blah blah
> auto words = split(sentence, regex("[ \t,.;:?]+"));
> // blah blah blah
> 
> 
> and two compilers (gdc, dmd) are giving me this error (output from gdc):
> 
> main.d:34: Error: std.string.split at
> /usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.1/../../../../include/d2/4.5.1/st
> d/string.d:69 conflicts with std.regex.split(String) at
> /usr/lib/gcc/x86_64-unknown-linux-gnu/4.5.1/../../../../include/d2/4.5.1/st
> d/regex.d:3096
> 
> 
> And I am clueless. How can they conflict, it's the standard library. It
> must be in the usage of split. As this is the second or third example in
> chapter one, I have no clue what is going on.

If both regex and string have a split function and the compiler can't tell 
which one you mean, then you're going to have to tell the compiler which split 
you mean, because there's an ambiguity. So, assuming that the split that you 
mean is the one in std.string, then you'd do

auto words = std.string.split(sentence, regex("[ \t,.;:?]+"));

Another option would be to use an alias such as

alias std.string.split split;

so that the whole module assumes that split is the one from std.string. Also, 
while for the most part, dmd follows TDPL, in some cases, TDPL is ahead and 
dmd hasn't implemented certain things yet. In addition, as far as the standard 
library goes, TDPL is not trying to really introduce or explain it for the 
most part, and in some cases, the standard library may have changed somewhat 
(though generally not drastically) from what's in the book. So, while _most_ 
examples will compile, some won't.

You should check out the errata page here: 
http://erdani.com/tdpl/errata/index.php?title=Main_Page

It also gives you the code for all of the examples as well as telling you 
which should currently work.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list