digitalmars.D.learn - Basic Syntax Question
- WhatMeWorry (17/17) Apr 02 2013 I don't suppose there is a digital.D.beginner forum?
- Tobias Pankrath (11/18) Apr 02 2013 Read it left to right :-)
- John Colvin (3/11) Apr 02 2013 Just a } vs ] typo (just to avoid confusion)
- John Colvin (13/30) Apr 02 2013 I'm confused, did you find that definition somewhere or did you
- WhatMeWorry (5/7) Apr 02 2013 I found the above in an example in std.conv; Thank you, but I can
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (13/17) Apr 02 2013 alias usually makes the syntax cleaner but that is still pretty crazy. :...
I don't suppose there is a digital.D.beginner forum? I've been staring at this definition for about an hour and I still can't decode it. int[string][double[int[]]] a; // ... auto b = to!(short[wstring][string[double[]]])(a); // this doesn't help either int[string} a // would be an Associate Array of integers with a string key? int[] // would be a dynamic array of integers,i believe? But put the int[] inside of double[] and put that inside of [] and put that after the associative array, and my head can't stop for spinning. If there is a better site or forum, please tell me and I won't waste people's time here. I did buy Andrei Alexandrescu's book and have it pretty well dog-eared. But i must be a pretty mediocre programmer.
Apr 02 2013
On Tuesday, 2 April 2013 at 16:24:46 UTC, WhatMeWorry wrote:I don't suppose there is a digital.D.beginner forum?There is D.learn. Scroll down in the webinterface :-)I've been staring at this definition for about an hour and I still can't decode it. int[string][double[int[]]] a; //Read it left to right :-) Let's rewrite the type with placeholders U,V. int[string][double[int[]]] --> int[U][V] int[U][V] is an AA mapping keys of type V to values int[U], which is itself an AA that maps U's to int's. Now, what is U and V? U is string that was easy. V is double[int[]]. That again is an AA, mapping from int[] to double.int[string} a // would be an Associate Array of integers with a string key?Nope, thats in syntax error.int[] // would be a dynamic array of integers,i believe?Correct.
Apr 02 2013
On Tuesday, 2 April 2013 at 16:51:45 UTC, Tobias Pankrath wrote:On Tuesday, 2 April 2013 at 16:24:46 UTC, WhatMeWorry wrote:This is in D.learn already.I don't suppose there is a digital.D.beginner forum?There is D.learn. Scroll down in the webinterface :-)Just a } vs ] typo (just to avoid confusion)int[string} a // would be an Associate Array of integers with a string key?Nope, thats in syntax error.
Apr 02 2013
On Tuesday, 2 April 2013 at 16:24:46 UTC, WhatMeWorry wrote:I don't suppose there is a digital.D.beginner forum? I've been staring at this definition for about an hour and I still can't decode it. int[string][double[int[]]] a; // ... auto b = to!(short[wstring][string[double[]]])(a); // this doesn't help either int[string} a // would be an Associate Array of integers with a string key? int[] // would be a dynamic array of integers,i believe? But put the int[] inside of double[] and put that inside of [] and put that after the associative array, and my head can't stop for spinning. If there is a better site or forum, please tell me and I won't waste people's time here. I did buy Andrei Alexandrescu's book and have it pretty well dog-eared. But i must be a pretty mediocre programmer.I'm confused, did you find that definition somewhere or did you write it yourself? int[string][double[int[]]] Let's split it up: alias double[int[]] T; T is an associative array with key type int[] and value type double So we now have int[string][T] Which is an associative array with key type T and value type int[string] (itself an associative array) I hope that makes more sense.
Apr 02 2013
On Tuesday, 2 April 2013 at 16:52:17 UTC, John Colvin wrote: int[string][double[int[]]] a;I'm confused, did you find that definition somewhere or did you write it yourself?I found the above in an example in std.conv; Thank you, but I can assure you my brain is not powerful enough to come up with such a construct.
Apr 02 2013
On 04/02/2013 09:24 AM, WhatMeWorry wrote:>I don't suppose there is a digital.D.beginner forum? I've been staring at this definition for about an hour and I still can't decode it. int[string][double[int[]]] a; //alias usually makes the syntax cleaner but that is still pretty crazy. :) void main() { int[string][double[int[]]] a; alias Numbers = int[]; alias NumbersToDoubleDict = double[Numbers]; alias StringToIntDict = int[string]; alias CrazyDict = StringToIntDict[NumbersToDoubleDict]; CrazyDict b; static assert(is(typeof(a) == typeof(b))); } Ali
Apr 02 2013