Arrays

An array variable is simply a collection of many variables of the same type.
In Mel, arrays are especially easy to work with.  You can add on to them whenever you want
without worrying about memory allocation whatsoever.
Create an array by putting [] after the variable name when you declare it.
After the array is created you can access its members by putting a number inside the [].

Remember: Array counting starts from zero, not one. Thats the way computers count, and it's important to get used to it because it makes working with them a lot easier. { int $array[]; $array[0] = 10; $array[1] = 13; $array[2] = 99; print $array; } An array in Mel can have as many members as you want, but remember, if you skip over some elements in your numbering, the parts you missed still count. { int $array[]; $array[0] = 10; $array[1] = 13; $array[37] = 99; print $array; } The default value of a numeric array member is 0. A default string array member is "", or nothing at all. You can get the size of an array by using the size command. { int $array[]; print ("size is " + `size $array` + "\n"); $array[0] = 10; $array[1] = 23; print ("size is " + `size $array` + "\n"); } For more info on whats going on inside those print commands read this about strings. For more info about `size $array` read this about return values.
The size of an array is figured starting from one. If there is one element with something in it, the array has a size of 1. Simple enough. What's nice about this is since array numbering begins at zero, you can use the size to add on to the end of the array. { int $array[]; print ("size is " + `size $array` + "\n"); $array[`size $array`] = 12; print ("size is " + `size $array` + "\n"); print $array; $array[`size $array`] = 54; print ("size is " + `size $array` + "\n"); print $array; $array[`size $array`] = 56; print ("size is " + `size $array` + "\n"); print $array; }
Which brings up another point; you don't have to use a number inside the [] to access a member. You can use variables as well, but they should be integers, and the value has to be positive. To initialize an array with values use this syntax: int $array[] = {12, 32, 46, 81, 78}; To clean up an array so it is empty again use the clear command. { int $array[] = {12, 32, 46, 81, 78}; print (`size $array` + "\n"); clear $array; print (`size $array` + "\n"); } Thats all for now, but there's a lot more you can do with arrays, and you will see them very often.