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 :)

Reply via email to