Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
November 12, 2010 Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Is D supposed to be able to handle nested associative arrays ?
--
/Jacob Carlborg
|
November 12, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Should be. Are you having problems?
(I don't use them much, but fwiw, it seems like tango had some [trivial?] problems with them)
On 11/12/2010 10:08 AM, Jacob Carlborg wrote:
> Is D supposed to be able to handle nested associative arrays ?
>
>
|
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ellery Newcomer | On 2010-11-12 17:44, Ellery Newcomer wrote: > Should be. Are you having problems? > > (I don't use them much, but fwiw, it seems like tango had some > [trivial?] problems with them) > > On 11/12/2010 10:08 AM, Jacob Carlborg wrote: >> Is D supposed to be able to handle nested associative arrays ? >> >> Well, yes. The following code: module main; void main () { auto tree = ["" : ["" : ""]]; } Using DMD 1.065 results in: Assertion failed: (0), function toExpression, file init.c, line 437. -- /Jacob Carlborg |
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Jacob Carlborg:
> module main;
>
> void main ()
> {
> auto tree = ["" : ["" : ""]];
> }
>
> Using DMD 1.065 results in:
>
> Assertion failed: (0), function toExpression, file init.c, line 437.
Please put it in Bugzilla if not already present :-)
Bye,
bearophile
|
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 13/11/2010 11:02, Jacob Carlborg wrote: > On 2010-11-12 17:44, Ellery Newcomer wrote: >> Should be. Are you having problems? >> >> (I don't use them much, but fwiw, it seems like tango had some >> [trivial?] problems with them) >> >> On 11/12/2010 10:08 AM, Jacob Carlborg wrote: >>> Is D supposed to be able to handle nested associative arrays ? >>> >>> > > Well, yes. The following code: > > module main; > > void main () > { > auto tree = ["" : ["" : ""]]; > } > > Using DMD 1.065 results in: > > Assertion failed: (0), function toExpression, file init.c, line 437. > That's static initialisation not an AA. alias string[char] innerAA; alias innerAA[int] outerAA; outerAA x; innerAA t; x[2] = t; auto y = x[2]; y['c'] = "cat"; I've no idea what'll happen if you start passing it around though. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk |
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to div0 | On 2010-11-13 14:56, div0 wrote: > On 13/11/2010 11:02, Jacob Carlborg wrote: >> On 2010-11-12 17:44, Ellery Newcomer wrote: >>> Should be. Are you having problems? >>> >>> (I don't use them much, but fwiw, it seems like tango had some >>> [trivial?] problems with them) >>> >>> On 11/12/2010 10:08 AM, Jacob Carlborg wrote: >>>> Is D supposed to be able to handle nested associative arrays ? >>>> >>>> >> >> Well, yes. The following code: >> >> module main; >> >> void main () >> { >> auto tree = ["" : ["" : ""]]; >> } >> >> Using DMD 1.065 results in: >> >> Assertion failed: (0), function toExpression, file init.c, line 437. >> > That's static initialisation not an AA. > > alias string[char] innerAA; > alias innerAA[int] outerAA; > > outerAA x; > innerAA t; > > x[2] = t; > > auto y = x[2]; > y['c'] = "cat"; > > I've no idea what'll happen if you start passing it around though. How about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure. -- /Jacob Carlborg |
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile | On 2010-11-13 14:39, bearophile wrote: > Jacob Carlborg: > >> module main; >> >> void main () >> { >> auto tree = ["" : ["" : ""]]; >> } >> >> Using DMD 1.065 results in: >> >> Assertion failed: (0), function toExpression, file init.c, line 437. > > Please put it in Bugzilla if not already present :-) > > Bye, > bearophile Done: http://d.puremagic.com/issues/show_bug.cgi?id=5211 -- /Jacob Carlborg |
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | Wow.
Yeah, I guess all bets are off when it comes to initializations.
In the meantime, I guess you'll have to use
string[string][string] tree;
tree = ["" : ["" : ""]];
On 11/13/2010 05:02 AM, Jacob Carlborg wrote:
> Well, yes. The following code:
>
> module main;
>
> void main ()
> {
> auto tree = ["" : ["" : ""]];
> }
>
> Using DMD 1.065 results in:
>
> Assertion failed: (0), function toExpression, file init.c, line 437.
>
|
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jacob Carlborg | On 13/11/2010 15:49, Jacob Carlborg wrote: > On 2010-11-13 14:56, div0 wrote: >> On 13/11/2010 11:02, Jacob Carlborg wrote: >>> On 2010-11-12 17:44, Ellery Newcomer wrote: >>>> Should be. Are you having problems? >>>> >>>> (I don't use them much, but fwiw, it seems like tango had some >>>> [trivial?] problems with them) >>>> >>>> On 11/12/2010 10:08 AM, Jacob Carlborg wrote: >>>>> Is D supposed to be able to handle nested associative arrays ? >>>>> >>>>> >>> >>> Well, yes. The following code: >>> >>> module main; >>> >>> void main () >>> { >>> auto tree = ["" : ["" : ""]]; >>> } >>> >>> Using DMD 1.065 results in: >>> >>> Assertion failed: (0), function toExpression, file init.c, line 437. >>> >> That's static initialisation not an AA. >> >> alias string[char] innerAA; >> alias innerAA[int] outerAA; >> >> outerAA x; >> innerAA t; >> >> x[2] = t; >> >> auto y = x[2]; >> y['c'] = "cat"; >> >> I've no idea what'll happen if you start passing it around though. > > How about "associative array literal" then? Regardless of what you call > it I shouldn't get an assertion failure. > True. It's been fixed in dmd2 though, you get: Error: Integer constant expression expected instead of "" When it's auto the compiler thinks you are doing static initialisation of a flat array, not an AA. You have to do what Ellery said. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk |
November 13, 2010 Re: Nested associative arrays | ||||
---|---|---|---|---|
| ||||
Posted in reply to div0 | On Sat, 13 Nov 2010 17:27:08 +0000
div0 <div0@sourceforge.net> wrote:
> > How about "associative array literal" then? Regardless of what you call
> > it I shouldn't get an assertion failure.
> >
>
> True. It's been fixed in dmd2 though, you get:
>
> Error: Integer constant expression expected instead of ""
>
> When it's auto the compiler thinks you are doing static initialisation of a flat array, not an AA. You have to do what Ellery said.
But the compiler (D2) accepts nested aa literals remaining anonymous:
writeln(["a" : ["b" : "c"]]); // --> "a:b:c"
(where "auto aa = ..." fails)
Denis
-- -- -- -- -- -- --
vit esse estrany ☣
spir.wikidot.com
|
Copyright © 1999-2021 by the D Language Foundation