This code creates one record variable (r
) and one tuple variable (t
) that contain several arrays and prints them to stdout:
const N = 5;
record Myrec {
var a: [1..N] int = (for i in 1..N do i);
var b: [1..N] int = (for i in 1..N do i);
var c: [1..N] int = (for i in 1..N do i);
}
proc test() {
var r: Myrec;
var t = (r.a, r.b, r.c);
writeln( "r = ", r );
writeln( "t = ", t );
}
test();
If I run this code, I get this output:
r = (a = 1 2 3 4 5, b = 1 2 3 4 5, c = 1 2 3 4 5)
t = (1 2 3 4 5, 1 2 3 4 5, 1 2 3 4 5)
but I feel the output is not very readable (particularly in the case of t
). So, I am wondering if there is some way to print such variables with square brackets, e.g., like the following?
t = ([1 2 3 4 5], [1 2 3 4 5], [1 2 3 4 5])
I think it can be achieved by using writef()
+ a format string + passing each field of the tuple (or write a specific function for that purpose), but it would be nice if there is some convenient way to achieve a similar goal...