Is there a matrix/array equivalent of [a,b,c]?

I often find myself in a situation where it is convenient to create matrices or arrays with various objects in them. For vectors, the syntax [a,b,c] will create a vector that holds variables a, b, and c, no matter what the types of these object are. I would like to know if there is some similar way of creating matrices or higher-dimensional arrays.

The operators ;, ;; and so on can be used to concatenate in various dimensions (which is useful in its own right), but this will not always work to create an array of e.g., strings or functions. For example, in julia v1.7.3 ["A" "B"; "C" "D"]
works, but ["A";"C";;"B";"D"] does not (it used to in v1.7.2). If you want a matrix with arrays in it, say

[ [1,2]   [1,2,3] 
  [2,4,5] [7,8,9,10] ]

the best I’ve come up with is

reshape( [ [1,2] , [2,4,5] , [1,2,3] , [7,8,9,10] ] , 2 , 2 )

None of this functionality is strictly necessary, but I construct objects like these often enough that I was curious if anyone knows any syntax, or possibly a macro, that would make constructing such objects more convenient.

You need extra brackets:

julia> [ [[1,2]]   [[1,2,3]]
         [[2,4,5]] [[7,8,9,10]] ]
2×2 Matrix{Vector{Int64}}:
 [1, 2]     [1, 2, 3]
 [2, 4, 5]  [7, 8, 9, 10]

That does not work without those extra braces?(can’t test now).

No, it doesn’t (in 1.7.2) and the error message is logical in this case:

ERROR: ArgumentError: mismatched height in block row 1 (expected 2, got 3)
1 Like

Indeed. I was quite wrong, a pity, I liked that :frowning: , seemed consistent with the syntax for building matrices from scalars.

Perfect, thank, you!

This is a bug. Something that used to work in v1.7.2 should continue to work. Please file an issue:

Alright, issue filed: