Julia 1.7 added the capacity to use the multiple semicolon syntax to initialise hard-coded arrays:
" Repeated semicolons can now be used inside array concatenation expressions to separate dimensions of an array, with the number of semicolons specifying the dimension. Just as a single semicolon in [A; B]
has always described concatenating in the first dimension (vertically), now two semicolons [A;; B]
do so in the second dimension (horizontally), three semicolons ;;;
in the third, and so on (#33697)."
julia> foo = [0; 0;; 0; 1;;; 0; 0;; 0; 1;;; 0; 0;; 0; 1;;; ]
2×2×3 Array{Int64, 3}:
[:, :, 1] =
0 0
0 1
[:, :, 2] =
0 0
0 1
[:, :, 3] =
0 0
0 1
However this didn’t work for other objects like tuples (just discovered…):
julia> foo = [(0,0); (0,0);; (0,0); (1,1);;; (0,0); (0,0);; (0,0); (1,1);;; (0,0); (0,1);; (0,1); (1,1);;; ]
ERROR: ArgumentError: invalid tuple dimension 2
This seems to have been resolved in Julia v1.8:
julia> foo = [(0,0); (0,0);; (0,0); (1,1);;; (0,0); (0,0);; (0,0); (1,1);;; (0,0); (0,1);; (0,1); (1,1);;; ]
2×2×3 Array{Tuple{Int64, Int64}, 3}:
[:, :, 1] =
(0, 0) (0, 0)
(0, 0) (1, 1)
[:, :, 2] =
(0, 0) (0, 0)
(0, 0) (1, 1)
[:, :, 3] =
(0, 0) (0, 1)
(0, 1) (1, 1)
However this is not recognised in the v1.8 release notes, where only a note on initialising empty array is given:
“Empty n-dimensional arrays can now be created using multiple semicolons inside square brackets, e.g. [;;;]
creates a 0×0×0 Array
(#41618).”
I think this is such fundamental that it should deserve a word on the release notes…