Thread overview
aa literals
Mar 13, 2010
Ellery Newcomer
Mar 13, 2010
bearophile
Mar 13, 2010
Philippe Sigaud
Mar 14, 2010
bearophile
Mar 14, 2010
Ellery Newcomer
Mar 14, 2010
bearophile
March 13, 2010
anyone know of a good (or any) syntax for an empty aa

impetus:

auto aa = reduce!(g)(emptyaa, lst);
March 13, 2010
Ellery Newcomer:

> anyone know of a good (or any) syntax for an empty aa

Unfortunately "null" suffices where the function that receives knows the type of the AA it will receive. But I don't like this, a more typed style can be less bug prone.

So you can give a type to null:
cast(int[string])null

I have created a bit shorter template:
AA!(string, int)

But it doesn't gain much.

Something similar can be used for dynamic arrays:
cast(int[])null
With dynamic arrays you can also use (that I don't like) "null" and even the special []

Bye,
bearophile
March 13, 2010
On Sat, Mar 13, 2010 at 20:17, Ellery Newcomer <ellery-newcomer@utulsa.edu>wrote:

> anyone know of a good (or any) syntax for an empty aa
>
> impetus:
>
> auto aa = reduce!(g)(emptyaa, lst);
>

To associate a list of key/value pairs into one AA?

I use .init, but AA in general have become buggy for the past few releases.

auto aa = reduce!g((V[K]).init, lst); // this used to work, I think

But, as I said, it has become quite buggy recently:

auto aa = (int[string]).init; // empty AA?
aa["abc"] = 3; // error, no operator [] overload for
AssociativeArray!(string, int). I mean, come on.


Philippe


March 14, 2010
Ellery Newcomer:
> anyone know of a good (or any) syntax for an empty aa
> impetus:
> auto aa = reduce!(g)(emptyaa, lst);

Sorry, I have probably not understood your question.

Bye,
bearophile
March 14, 2010
On 03/13/2010 07:20 PM, bearophile wrote:
> Ellery Newcomer:
>> anyone know of a good (or any) syntax for an empty aa
>> impetus:
>> auto aa = reduce!(g)(emptyaa, lst);
>
> Sorry, I have probably not understood your question.
>
> Bye,
> bearophile

No, you hit it on the head. Here's the kind of thing I was after:

auto g = reduce!("a[b]=1,a")(cast(int[int]) null, [1,2,3,4]);

Works fine. The one-liner probably isn't worth it, but I think it's pretty funny. What does this do to Walter's arguments concerning nonnull?
March 14, 2010
Ellery Newcomer:
>What does this do to Walter's arguments concerning nonnull?<

I don't understand the question, sorry.

Bye,
bearophile