digitalmars.D.learn - Nested associative arrays
- Jacob Carlborg (3/3) Nov 12 2010 Is D supposed to be able to handle nested associative arrays ?
- Ellery Newcomer (4/5) Nov 12 2010 Should be. Are you having problems?
- Jacob Carlborg (11/18) Nov 13 2010 Well, yes. The following code:
- bearophile (4/14) Nov 13 2010 Please put it in Bugzilla if not already present :-)
- Jacob Carlborg (4/18) Nov 13 2010 Done: http://d.puremagic.com/issues/show_bug.cgi?id=5211
- div0 (15/33) Nov 13 2010 That's static initialisation not an AA.
- Jacob Carlborg (5/39) Nov 13 2010 How about "associative array literal" then? Regardless of what you call
- div0 (8/50) Nov 13 2010 True. It's been fixed in dmd2 though, you get:
- spir (9/19) Nov 13 2010 But the compiler (D2) accepts nested aa literals remaining anonymous:
- div0 (9/28) Nov 13 2010 yeah, but dmd's parser was written by hand so it's not surprising there
- bearophile (5/8) Nov 13 2010 One of my many enhancement requests, no one disturbs their sleep in Bugz...
- spir (11/16) Nov 14 2010 Well, most (all?) truely used languages have hand-written parsers, AFAIK...
- spir (9/14) Nov 14 2010 =20
- Ellery Newcomer (10/14) Nov 13 2010 The difference is initializer vs expression.
- div0 (8/24) Nov 13 2010 Yeah I know. :( I've been working on implementing some missing CTFE
- Jacob Carlborg (6/55) Nov 14 2010 Well, that's no fun. How many are using the Static Initialization of
- Ellery Newcomer (6/14) Nov 13 2010 Wow.
Is D supposed to be able to handle nested associative arrays ? -- /Jacob Carlborg
Nov 12 2010
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 ?
Nov 12 2010
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: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 CarlborgIs D supposed to be able to handle nested associative arrays ?
Nov 13 2010
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
Nov 13 2010
On 2010-11-13 14:39, bearophile wrote:Jacob Carlborg:Done: http://d.puremagic.com/issues/show_bug.cgi?id=5211 -- /Jacob Carlborgmodule 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
Nov 13 2010
On 13/11/2010 11:02, Jacob Carlborg wrote:On 2010-11-12 17:44, Ellery Newcomer wrote: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.ukShould 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: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.Is D supposed to be able to handle nested associative arrays ?
Nov 13 2010
On 2010-11-13 14:56, div0 wrote:On 13/11/2010 11:02, Jacob Carlborg wrote:How about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure. -- /Jacob CarlborgOn 2010-11-12 17:44, Ellery Newcomer wrote: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.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: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.Is D supposed to be able to handle nested associative arrays ?
Nov 13 2010
On 13/11/2010 15:49, Jacob Carlborg wrote:On 2010-11-13 14:56, div0 wrote: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.ukOn 13/11/2010 11:02, Jacob Carlborg wrote:How about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure.On 2010-11-12 17:44, Ellery Newcomer wrote: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.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: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.Is D supposed to be able to handle nested associative arrays ?
Nov 13 2010
On Sat, 13 Nov 2010 17:27:08 +0000 div0 <div0 sourceforge.net> wrote:But the compiler (D2) accepts nested aa literals remaining anonymous: writeln(["a" : ["b" : "c"]]); // --> "a:b:c" (where "auto aa =3D ..." fails) Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.comHow about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure. =20=20 True. It's been fixed in dmd2 though, you get: =20 Error: Integer constant expression expected instead of "" =20 When it's auto the compiler thinks you are doing static initialisation=20 of a flat array, not an AA. You have to do what Ellery said.
Nov 13 2010
On 13/11/2010 20:02, spir wrote:On Sat, 13 Nov 2010 17:27:08 +0000 div0<div0 sourceforge.net> wrote:yeah, but dmd's parser was written by hand so it's not surprising there are inconsistency's with what works where. I finally found the bit where it describes associative array literals and they look identical to initialising a flat array, so god only knows which one gets picked when. It would be better if they where made different. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.ukBut 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.comHow 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.
Nov 13 2010
div0:I finally found the bit where it describes associative array literals and they look identical to initialising a flat array, so god only knows which one gets picked when. It would be better if they where made different.One of my many enhancement requests, no one disturbs their sleep in Bugzilla :-) http://d.puremagic.com/issues/show_bug.cgi?id=4703 Bye, bearophile
Nov 13 2010
On Sun, 14 Nov 2010 00:03:48 +0000 div0 <div0 sourceforge.net> wrote:yeah, but dmd's parser was written by hand so it's not surprising there=20 are inconsistency's with what works where.Well, most (all?) truely used languages have hand-written parsers, AFAIK. T= he issue is not with writing the parser, I guess, but with having a clear, = unambiguous, complete, definition of the language ;-)I finally found the bit where it describes associative array literals=20 and they look identical to initialising a flat array, so god only knows=20 which one gets picked when. It would be better if they where made differe=nt. ... with the tiny difference AAs are supposed to have (explicite) keys ;-) Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 14 2010
On Sun, 14 Nov 2010 10:35:42 +0100 spir <denis.spir gmail.com> wrote:=20I finally found the bit where it describes associative array literals=20 and they look identical to initialising a flat array, so god only knows=rent. =20which one gets picked when. It would be better if they where made diffe==20 ... with the tiny difference AAs are supposed to have (explicite) keys ;-)Oops, sorry for the noise... Denis -- -- -- -- -- -- -- vit esse estrany =E2=98=A3 spir.wikidot.com
Nov 14 2010
On 11/13/2010 02:02 PM, spir wrote:On Sat, 13 Nov 2010 17:27:08 +0000 But the compiler (D2) accepts nested aa literals remaining anonymous: writeln(["a" : ["b" : "c"]]); // --> "a:b:c" (where "auto aa = ..." fails)The difference is initializer vs expression. initializers occur on the rhs of a decl/assignment, and they are not parsed the same as expressions (e.g. you can have 'void' and struct literals as initializers - int i = void; X x = {a: {b: 1}, c: "hi"}; - you can't have these in expressions). Initializers are also stored and treated differently in the compiler, which results in this and other inconsistencies
Nov 13 2010
On 14/11/2010 00:28, Ellery Newcomer wrote:On 11/13/2010 02:02 PM, spir wrote:OIC, ty.On Sat, 13 Nov 2010 17:27:08 +0000 But the compiler (D2) accepts nested aa literals remaining anonymous: writeln(["a" : ["b" : "c"]]); // --> "a:b:c" (where "auto aa = ..." fails)The difference is initializer vs expression. initializers occur on the rhs of a decl/assignment, and they are not parsed the same as expressions (e.g. you can have 'void' and struct literals as initializers - int i = void; X x = {a: {b: 1}, c: "hi"}; - you can't have these in expressions).Initializers are also stored and treated differently in the compiler, which results in this and other inconsistenciesYeah I know. :( I've been working on implementing some missing CTFE functionality so that one day I might actually get to upgrade from 2.028, and having dealing with initializers vs expressions is a real pita. -- My enormous talent is exceeded only by my outrageous laziness. http://www.ssTk.co.uk
Nov 13 2010
On 2010-11-13 18:27, div0 wrote:On 13/11/2010 15:49, Jacob Carlborg wrote:Well, that's no fun. How many are using the Static Initialization of Static Arrays syntax: http://www.digitalmars.com/d/2.0/arrays.html#static-init-static ? -- /Jacob CarlborgOn 2010-11-13 14:56, div0 wrote: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.On 13/11/2010 11:02, Jacob Carlborg wrote:How about "associative array literal" then? Regardless of what you call it I shouldn't get an assertion failure.On 2010-11-12 17:44, Ellery Newcomer wrote: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.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: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.Is D supposed to be able to handle nested associative arrays ?
Nov 14 2010
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.
Nov 13 2010