Thread overview | ||||||
---|---|---|---|---|---|---|
|
December 24, 2010 Re: TDPL dictionary example - error | ||||
---|---|---|---|---|
| ||||
Attachments:
| Friday 24 December 2010 @ 06:24:34 Caligo:
> Greetings,
>
> I just joined here, so sorry if this has been posted before.
>
> I'm reading TDPL and the example on page 8 doesn't compile. I'm using the latest GDC with GCC 4.4.5. I've checked the errata, but nothing for this error.
>
> import std.stdio;
> import std.string;
>
> void main(){
>
> size_t[char[]] dictionary;
> foreach(line; stdin.byLine()){
> foreach(word; splitter(strip(line))){
> if(word in dictionary) continue;
> auto newID = dictionary.length;
> dictionary[word] = newID;
> writeln(newID, '\t', word);
> }
> }
> //writeln(dictionary.length);
> }
>
>
> This is the error:
> dictionary.d:12: Error: associative arrays can only be assigned values with
> immutable keys, not char[]
>
> If i use immutable keys, it works, but it defeats the purpose. So what's wrong with the code?
It works for DMD, I think it's a GDC bug (i'm new in D too, so i might be wrong). Keep in mind that GDC implements only D 1.0 and book has D 2.0 code.
Sincerely,
Mariusz Gliwiński
|
December 24, 2010 Re: TDPL dictionary example - error | ||||
---|---|---|---|---|
| ||||
Attachments:
| No, GDC supports D1 and D2. Version 2.051 I think. I know I've compiled mine with D2 support.
2010/12/24 Mariusz Gliwiński <alienballance@gmail.com>
> Friday 24 December 2010 @ 06:24:34 Caligo:
> > Greetings,
> >
> > I just joined here, so sorry if this has been posted before.
> >
> > I'm reading TDPL and the example on page 8 doesn't compile. I'm using
> the
> > latest GDC with GCC 4.4.5. I've checked the errata, but nothing for this error.
> >
> > import std.stdio;
> > import std.string;
> >
> > void main(){
> >
> > size_t[char[]] dictionary;
> > foreach(line; stdin.byLine()){
> > foreach(word; splitter(strip(line))){
> > if(word in dictionary) continue;
> > auto newID = dictionary.length;
> > dictionary[word] = newID;
> > writeln(newID, '\t', word);
> > }
> > }
> > //writeln(dictionary.length);
> > }
> >
> >
> > This is the error:
> > dictionary.d:12: Error: associative arrays can only be assigned values
> with
> > immutable keys, not char[]
> >
> > If i use immutable keys, it works, but it defeats the purpose. So what's wrong with the code?
>
> It works for DMD, I think it's a GDC bug (i'm new in D too, so i might be wrong). Keep in mind that GDC implements only D 1.0 and book has D 2.0 code.
>
> Sincerely,
> Mariusz Gliwiński
>
|
December 24, 2010 Re: TDPL dictionary example - error | ||||
---|---|---|---|---|
| ||||
Attachments:
| I forgot to ask, what version of DMD are you using?
2010/12/24 Mariusz Gliwiński <alienballance@gmail.com>
> Friday 24 December 2010 @ 06:24:34 Caligo:
> > Greetings,
> >
> > I just joined here, so sorry if this has been posted before.
> >
> > I'm reading TDPL and the example on page 8 doesn't compile. I'm using
> the
> > latest GDC with GCC 4.4.5. I've checked the errata, but nothing for this error.
> >
> > import std.stdio;
> > import std.string;
> >
> > void main(){
> >
> > size_t[char[]] dictionary;
> > foreach(line; stdin.byLine()){
> > foreach(word; splitter(strip(line))){
> > if(word in dictionary) continue;
> > auto newID = dictionary.length;
> > dictionary[word] = newID;
> > writeln(newID, '\t', word);
> > }
> > }
> > //writeln(dictionary.length);
> > }
> >
> >
> > This is the error:
> > dictionary.d:12: Error: associative arrays can only be assigned values
> with
> > immutable keys, not char[]
> >
> > If i use immutable keys, it works, but it defeats the purpose. So what's wrong with the code?
>
> It works for DMD, I think it's a GDC bug (i'm new in D too, so i might be wrong). Keep in mind that GDC implements only D 1.0 and book has D 2.0 code.
>
> Sincerely,
> Mariusz Gliwiński
>
|
December 24, 2010 Re: TDPL dictionary example - error | ||||
---|---|---|---|---|
| ||||
Attachments:
| Friday 24 December 2010 @ 18:36:08 Caligo:
> I forgot to ask, what version of DMD are you using?
2.049
|
Copyright © 1999-2021 by the D Language Foundation