Thread overview | |||||
---|---|---|---|---|---|
|
October 20, 2013 Error: no property 'sort' for type 'ulong[string]', or sometimes not ... | ||||
---|---|---|---|---|
| ||||
Hi there, So I've just stated learning D. Playing with associative arrays, I wrote this simple function. No big deal. void associativeArrayFu(){ ulong[string] arr; arr["foo"]=1; arr["bar"]=2; arr["foo"]=45; foreach( thing;arr.sort){ writeln( thing ); } } Compiles and runs just fine. Stating to have a bunch of funtions in one file, I reorganised my sources among several files (in the same project in Eclipse). Now the same function yelds this error when compiling: Error: no property 'sort' for type 'ulong[string]' wether it is in a source file alongside other functions, alone in its own file, or even all alone in its own project. Not that I care that much about this poor function, but I am puzzled. What did I miss ? And oh, maybe this is not the right place for a beginner ? Is there any better place ? |
October 20, 2013 Re: Error: no property 'sort' for type 'ulong[string]', or sometimes not ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Derix | On Sunday, 20 October 2013 at 14:50:52 UTC, Derix wrote: > Hi there, > > So I've just stated learning D. Playing with associative arrays, I wrote this simple function. No big deal. > > void associativeArrayFu(){ > ulong[string] arr; > arr["foo"]=1; > arr["bar"]=2; > arr["foo"]=45; > > foreach( thing;arr.sort){ > writeln( thing ); > } > } > > Compiles and runs just fine. > Stating to have a bunch of funtions in one file, I reorganised my sources among several files (in the same project in Eclipse). > > Now the same function yelds this error when compiling: > > Error: no property 'sort' for type 'ulong[string]' > > wether it is in a source file alongside other functions, alone in its own file, or even all alone in its own project. > > Not that I care that much about this poor function, but I am puzzled. What did I miss ? Associative arrays are not sortable and have no defined order of element pairs. You can get an array of its values and sort that, by using the `values` property: --- import std.algorithm : sort; import std.stdio : writeln; foreach(value; aa.values.sort()) { writeln(value); } --- > And oh, maybe this is not the right place for a beginner ? Is there any better place ? The D.learn group is the most appropriate for these kinds of questions :) |
October 20, 2013 Re: Error: no property 'sort' for type 'ulong[string]', or sometimes not ... | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jakob Ovrum | > Associative arrays are not sortable and have no defined order of element pairs. Yep, that's definitely the point that I missed. >You can get an array of its values and sort > that, by using the `values` property: > --- > import std.algorithm : sort; > import std.stdio : writeln; > > foreach(value; aa.values.sort()) > { > writeln(value); > } > --- OK, I get the idea. I am still a bit removed from navigating the numerous libraries, but I'll guess I'll get used to it. >> And oh, maybe this is not the right place for a beginner ? Is there any better place ? > > The D.learn group is the most appropriate for these kinds of questions :) Yep, found out later that it was right in front of me, d'oh ;-) thanks a lot for your spot-on answers ! |
Copyright © 1999-2021 by the D Language Foundation