bearophile wrote:
Andrei Alexandrescu:
Great point. My hope is that one day I'll manage to convince Walter and Sean to simply replace V[K] types with AssocArray!(K, V) and then make AssocArray a regular template inside object.d. The current implementation of associative arrays looks... brutal.

Maybe some compromise can be found. I think the current syntax is good enough.

Yah. I see I created confusion - the surface syntax wouldn't change at all. Only the way the compiler translates it. In essence, aside from literals and type names, all expressions involving hashes should be handled like regular expressions.

A possible idea is to translate the current AA code to D and create a D module 
(that object imports, if you want) that contains something like that 
AssocArray!(K, V).
Some very useful things are missing in the current AAs:
- OpEquals among AAs, very useful in unit tests, to assert that functions 
return a correct AA.
- Empty AA literal (or expression, I currently use AA!(T, S)).
- Empty AAs can be false.
- A way to clear an AA, like aa.clear or aa.clear();
- A way to perform a shallow copy, like aa.dup
- Possibly lazy view of keys, values and key-value pairs, as in Java and 
Python3.
- A more precise management by the GC.

These are great ideas. I'd be glad to implement them but currently my hands are tied by the way things are handled today.

Then the compiler can map the current syntax to the AssocArray!(K, V) template 
struct/class and its functionality. I don't know if this can be done.
It's also a way to reduce the C code and translate some of it to D.

Nonono. What I'm saying is very simple: translate V[K] into AssocArray!(K, V) and [ k1:v1, k2:v2, ..., kn:vn ] into AssocArray!(typeof(k1), typeof(v1))(k1, v1, k2, v2, ..., kn, vn) and do exactly nothing else in particular about hashes.


Andrei

Reply via email to