NOPE[/code:1l4lru5h]An array, in traditional programming language (C/C++/C#, Java, Python,...) is a list of contiguous elements of the same size (in memory). No more, no less.
When saying "dynamically referable location" you probably mean that you can use a variable that can dynamically change to access any part of the array. And that's right.
However, you can access each element using an integer index. Not a string, only an integer.
For example, let say we have an array of 4bytes integers.
In C (let's get back to the bare basics) you would do[code:1l4lru5h] int myArray[10]; //create an array of 10 ints[/code:1l4lru5h]
This will exactly reserve 4*10 = 40bytes of memory.
if we were to represent the array in memory, we could imagine something like that:
[code:1l4lru5h]
indices : 0 1 2 3 4 5 6 7 8 9
schema: [int][int][int][int][int][int][int][int][int][int]
offsets : 0 4 8 12 16 20 24 28 32 36 40 ...
[/code:1l4lru5h]
So how does an array work its magic?
when you do myArray[7], the computer knowing that all element have 4bytes will look at the 7x4th byte from the start of the array
And indeed the int at index 7 is the one at the offset 28 byte.
That's how array works. No more, no less.
Now, there's something that might confuse people depending on how you use arrays in some programming languages.
[h2]Multi-dimensional arrays ARE NOT array of arrays![/h2]
A Multi-dimensional array is just an arithmetic trick. In memory, it's still a single line of contiguous data. However an Array of Array is an array of pointers to arrays spread over the memory.
In C, you declare a 2-dimensional array like this:
[code:1l4lru5h]int multiArray[2][3]; // initialise a 2D array. For clarity let say it has a height of 2 and a width of 3[/code:1l4lru5h]
here is what it looks like in memory:
[code:1l4lru5h]
indices1: 0 0 0 1 1 1
indices2: 0 1 2 0 1 2
schema: [int][int][int][int][int][int]
offsets: 0 4 8 12 16 20 24...
[/code:1l4lru5h]
if you want a value at index [1][2] you get the value at offset (indice1 * width + indice2) * size_of_int = (1 * 3 + 2) * 4 = 5*4 = 20
Now an array of array, in C is declared like this:
[code:1l4lru5h]int* arrayOfArray[3] // array of pointers to int. Or, for simplicity's sake: array of arrays of ints[/code:1l4lru5h]
The special character* means pointer to what is before it.
It means that you don't have an array of ints anymore, but an array of pointers to an int (yeah those iffy pointers is why people don't like C/C++).
For this short explanation, you just have to understand that an array of ints is under the hood a pointer to an int (the first of the array then you use the previously mentionned offset to traverse your memory). Then you can understand that as "array of pointers to an int", or more conceptually "array of arrays of ints"
in memory, it looks like
[code:1l4lru5h]
indices : 0 1 2 3
schema: [int*][int*][int*]
offsets : 0 4 8 12...
[/code:1l4lru5h]
(yeah pointers often also take 4 bytes but it depends on the compiler)
So when you do
[code:1l4lru5h]arrayOfArray[2][/code:1l4lru5h]
You basically get an array of int.
Obviously C allows you to get any value in this array as well, so you can do something like
[code:1l4lru5h]arrayOfArray[2][3][/code:1l4lru5h]
But what happens isn't the same as with the 2D array. Here you don't do arithmetics per se, you directly go to were a second array of int is, and use it directly like a simple array. A bit like Matryoshka doll or like following a path.
One of the main differences between the two, in practice, is that the arrays of your array of arrays can have different sizes (jagged arrays). It allows you for example, to build triangular matrices.[code:1l4lru5h][[3,2,1],
[2,1]
[1]][/code:1l4lru5h]
Using a multi-dimensional array, You you just always have the same width, height, depth,... So it's a good fit for square matrices.[code:1l4lru5h][1, 0, 0,
0, 1, 0
0, 0, 1][/code:1l4lru5h]
Small note about javascript:
Arrays in javascript are very far away from C arrays. They actually aren't really arrays but objects that expose a behavior close to arrays. Nonetheless, you can't access their elements by strings.
Also, "true" multidimensional array in javascript, and also php are impossible. People talking about multidimensional array in those language are merely refering to how they use it. But make no mistake, they are indeed Array of arrays in all case.
C2 array object aims to emulate the behavior of a true multidimensional array, that's why your can't easily have jagged arrays.
accessed by "string"
What you were refering to is called by many names. "Hashtable","Hashmap","Dictionary","Records",...
[rant]Basically it's a datastructure which allows you to access a value indexed using a hash.
Well usually, you don't use the hash but something that can be hashed (let say for example,... a string).
The hash will correspond to an index in an array of "bucket" (another kind of datastructure) which contains all value whose key have the same hash (hash collision).
The corresponding value is then inserted in or retrieved from this bucket.
A hashtable is slightly slower than an array. Since read and write require more computation. But it often doesn't matter.[/rant]
C2 dictionnary is just a simple basic hashtable.
This is the limiting factor of C2 where not being able build large complex structures like recursive functions or dynamic data algorithms (closed loop systems)
You can build recursive function in C2.
+ Function: "factorial"
+ Function: parameter 0 <= 1
-> Function: set return value to 1
+ else
-> Function: set return value to Function.param(0) * Function.call("factorial",Function.param(0) - 1)[/code:1l4lru5h]
Also, you can build complex datastructure as well with a few hacks, but since it involves passing and parsing JSON strings arround, it's very inefficient. And yeah there's no easy way to create things like circular linked list. It's not impossible, but it would require building a whole set of function interfaces to access some data a certain ways to simulate memory references. And safe is to say that we would move toward crippling efficiency. C2 is slow enough :D
I would advise to take a look at my [url=https://www.scirra.com/forum/plugin-json-import-export-generate-edit-inspect_t100042]JSON plugin[/url]. It's still in development but I'm using it at work and it simplify few things.
At home I already implemented the hability to load/save objects by reference. So you will be able to create any cyclic datastructure you want.
But since I have no cool ways to save that as json for debugging or saving, I'm still looking for a good solution.