An array is a compound data type; it's a group of values, possibly of different data types.
Arrays can be very useful when used in conjunction with foreach loops, which allow to execute a statements block once for every element in a given array. Also, Cows' arrays can replace standard variables when you define some strings grouped by a logical relationship.
A literal array is indicated by a list of variables separated by commas and enclosed by braces:
{ 1, 2, 3 } { "Meat", "Is", "Murder" } { 1, "foo", 2, "bar" }
A variable storing an array can optionally be followed by braces like foo
[ ] but it's not required. This notation can be useful to make
your sources more readable since arrays are easily identified. Moreover, an error will be
raised if you try to assign a scalar value to such variables. On the other hand, if you
don't use braces, the same variable can refer to scalar values and arrays under different
conditions. This adds flexibility to your code.
Important: notation doesn't
affect the way variables are stored: foo
and foo
[ ] are exactly the same variable. You can also mix both
notations:
foo [ ] = { 1, 2, 3 }; print (foo); print (foo [ ]);
Array foo will be displayed twice:
{ 1, 2, 3 } { 1, 2, 3 }
All this can seem confusing at first, and probably differs from the notation used by
your favorite scripting language (unless your favorite scripting language is G-Cows ...).
In the following sections we'll always use the notation foo
[ ] for the sake of clarity but remember that braces are optional.
This manual can be downloaded from http://www.g-cows.org/.