Skip to content
Browse files

Added description of multidimensional arrays (and indices), as well a…

…s a description of fixed arrays.
  • Loading branch information...
1 parent 0802b1f commit dfa82ca22184231f79e14c5b215370c942e501bb @fernozzle fernozzle committed
Showing with 44 additions and 3 deletions.
  1. +44 −3 winxed/syntaxandtypes.md
View
47 winxed/syntaxandtypes.md
@@ -106,8 +106,21 @@ including nested arrays:
"Hello"
];
-In these initializers, primitive types like integers, floats, and strings are
-automatically boxed to the storage type of the array. Notice the phrase
+Elements of arrays nested within arrays can be accessed with the addition of
+another identifier:
+
+ array[2, 1] //3, the second element of the third element
+
+This allows for the easy access of multidimensional arrays.
+
+ var colors = [
+ [["black", "blue"],["green", "cyan"]],
+ [["red", "pink"],["yellow", "white"]]
+ ];
+ colors[1, 0, 1]; //"pink"
+
+In the initializers shown, primitive types like integers, floats, and strings
+are automatically boxed to the storage type of the array. Notice the phrase
"storage type of the array". This is included because Parrot supports multiple
array types, of which ResizablePMCArray is just the most common. Also,
ResizablePMCArray is the type that is created with the bracket syntax. We can
@@ -117,6 +130,34 @@ also use a different type of array if we create it explicitly.
int_array[0] = 1;
int_array[1] = "43";
+Arrays of fixed sizes are named with `Fixed` instead of `Resizable`, and differ
+from resizable arrays in that a fixed array's length must be defined in the
+initialization, and cannot be altered at any point.
+
+ var fixed_int_array = new 'FixedIntegerArray'(3)
+ fixed_int_array[0] = 4;
+ fixed_int_array[1] = 8;
+ fixed_int_array[2] = 15;
+
+The previously depicted multidimensional array can be expressed through fixed
+arrays as such:
+
+ var colors = new 'FixedPMCArray'(2);
+ var colors[0] = new 'FixedPMCArray'(2);
+ var colors[0, 0] = new 'FixedStringArray'(2);
+ var colors[0, 0, 0] = "black";
+ var colors[0, 0, 1] = "blue";
+ var colors[0, 1] = new 'FixedStringArray'(2);
+ var colors[0, 1, 0] = "green";
+ var colors[0, 1, 1] = "cyan";
+ var colors[1] = new 'FixedPMCArray'(2);
+ var colors[1, 0] = new 'FixedStringArray'(2);
+ var colors[1, 0, 0] = "red";
+ var colors[1, 0, 1] = "pink";
+ var colors[1, 1] = new 'FixedStringArray'(2);
+ var colors[1, 1, 0] = "yellow";
+ var colors[1, 1, 1] = "white";
+
We will talk about other types of built-in PMCs and the `new` keyword a little
bit later.
@@ -290,4 +331,4 @@ You can use `try` and `catch` to catch exceptions and examine them.
// something dangerous here
} catch (e) {
// handle the exception here
- }
+ }

0 comments on commit dfa82ca

Please sign in to comment.
Something went wrong with that request. Please try again.