Hi,
I have an associative array with strings as keys and static
arrays as values. When I access a new key, it gives me Range
Error, so I think I should initialise the associative array, but
how?
here is the code that fails:
int[100][string] counts;
counts[some_key][20]++;
//
Am 21.03.2012 11:51, schrieb Stephan:
Hi,
I have an associative array with strings as keys and static arrays as
values. When I access a new key, it gives me Range Error, so I think I
should initialise the associative array, but how?
here is the code that fails:
int[100][string] counts;
On Wednesday, 21 March 2012 at 10:51:05 UTC, Stephan wrote:
Hi,
I have an associative array with strings as keys and static
arrays as values. When I access a new key, it gives me Range
Error, so I think I should initialise the associative array,
but how?
here is the code that fails:
Jesse's solution is correct, but I thought I'd throw in a
comment or two.
You are correct that the associative array is uninitialized
by default, and that you must initialize it. For very small
static arrays, a simple array literal like [1, 2, 3] would
suffice, but for larger arrays, this is a
Jesse Phillips:
int[100][string] counts;
int[100] a;
counts[some_key] = a;
counts[some_key][20]++;
Someone is currently trying to improve/fix AAs, this seems a
problem that is worth trying removing.
Bye,
bearophile
On Wed, Mar 21, 2012 at 04:15:18PM +0100, bearophile wrote:
Jesse Phillips:
int[100][string] counts;
int[100] a;
counts[some_key] = a;
counts[some_key][20]++;
Someone is currently trying to improve/fix AAs, this seems a
problem that is worth trying removing.
[...]
That
Thanks everyone. OK, so a temporary variable seems to be the most
obvious workaround, thanks Jesse. Thanks also to the others in
pointing out this issue.
All the best,
Stephan
On Wednesday, 21 March 2012 at 14:19:03 UTC, Jesse Phillips wrote:
On Wednesday, 21 March 2012 at 10:51:05 UTC,