digitalmars.D.learn - Array Concatenate
- Paul (10/10) Jun 08 2012 If this works...
- Paul (1/11) Jun 08 2012
- Dmitry Olshansky (6/22) Jun 08 2012 because it's associative array and it doesn't support "appending"
- Paul (3/24) Jun 08 2012 string[ulong] is a standard array
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (6/8) Jun 08 2012 No, they are both associative arrays. string[ulong] is a mapping from
- Dmitry Olshansky (9/34) Jun 08 2012 While I see logic, but no.
- Jonathan M Davis (14/28) Jun 08 2012 You didn't give us the types of either DeletedBlks or matchOld[0]. Howev...
- Nathan M. Swan (6/16) Jun 08 2012 It seems like you're confusing _associative_ arrays with
- Era Scarecrow (9/15) Jun 08 2012 I'd consider the Associative Array with any numeric key as a
If this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?
Jun 08 2012
On Friday, 8 June 2012 at 12:41:13 UTC, Paul wrote:If this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?
Jun 08 2012
On 08.06.2012 16:42, Paul wrote:On Friday, 8 June 2012 at 12:41:13 UTC, Paul wrote:because it's associative array and it doesn't support "appending" meaningfully ? AA with integer keys != plain arrays -- Dmitry OlshanskyIf this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?
Jun 08 2012
On Friday, 8 June 2012 at 12:50:56 UTC, Dmitry Olshansky wrote:On 08.06.2012 16:42, Paul wrote:string[ulong] is a standard array ulong[string] would be associative....NO?On Friday, 8 June 2012 at 12:41:13 UTC, Paul wrote:because it's associative array and it doesn't support "appending" meaningfully ? AA with integer keys != plain arraysIf this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?
Jun 08 2012
On 06/08/2012 07:50 AM, Paul wrote:string[ulong] is a standard array ulong[string] would be associative....NO?No, they are both associative arrays. string[ulong] is a mapping from ulong to string, ulong[string] is a mapping from string to ulong. Ali -- D Programming Language Tutorial: http://ddili.org/ders/d.en/index.html
Jun 08 2012
On 08.06.2012 18:50, Paul wrote:On Friday, 8 June 2012 at 12:50:56 UTC, Dmitry Olshansky wrote:While I see logic, but no. And the reason is that associative means non-contiguous, that is deletedBlks[0] is not next to deletedBlks[1] etc. More over there could be gaps.. And most important there is no order of elements. It's just a map: given integer - give a string. And plain arrays are more then that :) -- Dmitry OlshanskyOn 08.06.2012 16:42, Paul wrote:string[ulong] is a standard array ulong[string] would be associative....NO?On Friday, 8 June 2012 at 12:41:13 UTC, Paul wrote:because it's associative array and it doesn't support "appending" meaningfully ? AA with integer keys != plain arraysIf this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?
Jun 08 2012
On Friday, June 08, 2012 14:41:10 Paul wrote:If this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]);That compiles just fine.why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?You didn't give us the types of either DeletedBlks or matchOld[0]. However, from the error, it looks like DeletedBlks is a string[ulong], and matchOld[0] is a string. string[ulong] is an associate array - which means that it's a hash table - and appending doesn't make any sense with an associative array, because AAs aren't ordered. They take key-value pairs. So, something like DeletedBlks[42] = matchOld[0]; should compile - which creates the key-value pair of 42 and the value of matchOld[0]. Section 4.4 of TDPL discusses associative arrays (which you obviously aren't far from, since you're referring to section 4.1.9). So, read that section, and things should be clearer. - Jonathan M Davis
Jun 08 2012
On Friday, 8 June 2012 at 12:41:13 UTC, Paul wrote:If this works... D programming book section 4.1.9 Expanding auto a = [87, 40, 10]; a ~= 42; assert(a== [87, 40, 10, 42]); why doesnt' this work? DeletedBlks ~= matchOld[0]; the dmd compiler comes back with Error: cannot append type string to type string[ulong] Does this append operator only work for literals?It seems like you're confusing _associative_ arrays with _regular_ arrays; they are different things. A regular array is written as T[], or an array of Ts. An associative array is written as K[V], or a map from K to V. If you have a list of something, use string[], not string[ulong].
Jun 08 2012
On Friday, 8 June 2012 at 18:49:42 UTC, Nathan M. Swan wrote:It seems like you're confusing _associative_ arrays with _regular_ arrays; they are different things. A regular array is written as T[], or an array of Ts. An associative array is written as K[V], or a map from K to V. If you have a list of something, use string[], not string[ulong].I'd consider the Associative Array with any numeric key as a sparse array; Course like that you wouldn't get them in any particular order... And most of the time you wouldn't need to. I've found all kinds of interesting uses for numeric based AA's, one of them is one of my examples of an expanding prime number-generating range, another could be for a COW (Copy-on-write) based array; Reminds me I'll write a struct for one if there isn't one yet.
Jun 08 2012