digitalmars.D.learn - aa literals
- Ellery Newcomer <ellery-newcomer utulsa.edu> Mar 13 2010
- bearophile <bearophileHUGS lycos.com> Mar 13 2010
- Philippe Sigaud <philippe.sigaud gmail.com> Mar 13 2010
- bearophile <bearophileHUGS lycos.com> Mar 13 2010
- Ellery Newcomer <ellery-newcomer utulsa.edu> Mar 13 2010
- bearophile <bearophileHUGS lycos.com> Mar 14 2010
anyone know of a good (or any) syntax for an empty aa impetus: auto aa = reduce!(g)(emptyaa, lst);
Mar 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
Mar 13 2010
--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"><<a href=3D"mailto:ellery-newcomer utulsa.edu">= ellery-newcomer utulsa.edu</a>></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["abc"] =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
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
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
Ellery Newcomer:What does this do to Walter's arguments concerning nonnull?<
I don't understand the question, sorry. Bye, bearophile
Mar 14 2010









bearophile <bearophileHUGS lycos.com> 