Skip to content

Commit ea9c2a7

Browse files
committed
update: add example of 3D structure stream formatting
1 parent 5775ce1 commit ea9c2a7

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

gazprea/spec/globals.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ If functions have access to mutable global state then we can not guarantee
2525
their purity.
2626

2727
Globals must be initialized, but the initialization expressions may only contain
28-
a single _scalar_ literal. That means that functions and even previously defined globals may not
28+
a single scalar literal. That means that functions and even previously defined globals may not
2929
appear on the RHS of a global declaration. The reason is because it is very difficult to
3030
evaluate variables and functions at compile time. Global expression evaluation could
3131
be deferred to runtime, but that has the disadvantage of changing errors from compile

gazprea/spec/types/vector.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,19 @@ within the vector, and the second index selects the element within the array:
7979
vector<real[*]> ragged_right = [[1.0], [2.1]];
8080
length(ragged_right[1]) -> std_output; // prints 1
8181
ragged_right[2][1] -> std_output; // prints 2.1
82+
83+
Stream Formatting
84+
~~~~~~~~~~~~~~~~~
85+
86+
Printing a vector of two-dimensional arrays necessitates defining the formatting of a three-dimensional structure. The rules extend naturally from the 2D case.
87+
88+
::
89+
90+
var vector<integer[2][2]> v;
91+
v.push([[1,2], [3,4]]);
92+
v.push([[5,6], [7,8]]);
93+
94+
// prints [[[5 6] [7 8]] [[1 2] [3 4]]]
95+
reverse(v) -> std_output;
96+
97+

0 commit comments

Comments
 (0)