Pulling some builtin logic out

Kaja kaja.fumei at gmail.com
Tue Apr 1 05:15:53 PDT 2008


Robert Fraser Wrote:

> Kaja wrote:
> > Walter wrote in the docs:
> >> Associative Arrays
> >>
> >> The main benefit for this is, once again, syntactic sugar. An
> >> associative array keying off of a type T and storing an int value is
> >> naturally written as: 
> >>
> >> int[T] foo;
> >> rather than: 
> >>
> >> import std.associativeArray;
> >> ...
> >> std.associativeArray.AA!(T, int) foo;
> >> Builtin associative arrays also offer the possibility of having associative
> >> array literals, which are an often requested additional feature. 
> > 
> > And he's not big on standrdizing a library, but what if we could have the syntactic sugar and flexibility?  What if int[T] mapped to an interface for associative arrays rather than a class or builtin type?  Standardize the interface and not the implementation.
> > 
> > Then someone could still do something like this:
> > 
> > class MyAA(K, V) : std.associativeArray(K, V)
> > {
> >   // insert my implementation
> > }
> > 
> > // compiler choice.  probably builtin implementation
> > int[string] foo;
> > 
> > // programmer choice.
> > int[string] foo2 = new MyAA!(string, int)();
> > 
> > Thoughts?  Comments?
> 
> I'd assume the user would be given some control, so she could, say, use 
> Judy ( http://judy.sourceforge.net ) or her own implementation rather 
> than a built-in/standard library implementation and look down on 
> everyone else's cache inefficiencies?

Yeah, the purpose of this suggestion is so that D would define an interface for associate arrays (and potentially other builtin types) so that the programmer can use any class implements that interface regardless of whether its in a standard, third party, or custom deisgned library.



More information about the Digitalmars-d mailing list