www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - aa literals

reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
anyone know of a good (or any) syntax for an empty aa

impetus:

auto aa = reduce!(g)(emptyaa, lst);
Mar 13 2010
next sibling parent bearophile <bearophileHUGS lycos.com> writes:
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
Mar 13 2010
prev sibling next sibling parent Philippe Sigaud <philippe.sigaud gmail.com> writes:
--0015175883c8a5518a0481b576c4
Content-Type: text/plain; charset=ISO-8859-1

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 --0015175883c8a5518a0481b576c4 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <br><br><div class=3D"gmail_quote">On Sat, Mar 13, 2010 at 20:17, Ellery Ne= wcomer <span dir=3D"ltr">&lt;<a href=3D"mailto:ellery-newcomer utulsa.edu">= ellery-newcomer utulsa.edu</a>&gt;</span> wrote:<br><blockquote class=3D"gm= ail_quote" style=3D"margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(2= 04, 204, 204); padding-left: 1ex;"> anyone know of a good (or any) syntax for an empty aa<br> <br> impetus:<br> <br> auto aa =3D reduce!(g)(emptyaa, lst);<br></blockquote><div><br>To associate= a list of key/value pairs into one AA?<br><br>I use .init, but AA in gener= al have become buggy for the past few releases.<br><br>auto aa =3D reduce!g= ((V[K]).init, lst); // this used to work, I think<br> <br>But, as I said, it has become quite buggy recently:<br><br>auto aa =3D = (int[string]).init; // empty AA?<br>aa[&quot;abc&quot;] =3D 3; // error, no= operator [] overload for AssociativeArray!(string, int). I mean, come on.<= br> <br><br>Philippe<br></div></div> --0015175883c8a5518a0481b576c4--
Mar 13 2010
prev sibling parent reply bearophile <bearophileHUGS lycos.com> writes:
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
Mar 13 2010
parent reply Ellery Newcomer <ellery-newcomer utulsa.edu> writes:
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?
Mar 13 2010
parent bearophile <bearophileHUGS lycos.com> writes:
Ellery Newcomer:
What does this do to Walter's arguments concerning nonnull?<

I don't understand the question, sorry. Bye, bearophile
Mar 14 2010