The documentation for show
states: “Write a text representation of a value x
… and should be parseable Julia code when possible”. So I took that to mean that show
and Main.eval(Meta.parse())
should (if poss) be inverses of one-another.
For arrays of Number
s, they generally are inverses. But not in the case of a two-dimensional array with a single column, for which I find that “showing then parsing” converts from two dimensions to one dimension".
What “array literal” will be parse
d to a Matrix
with one column?
julia> function myshow(x)
io = IOBuffer()
show(io,x)
String(take!(io))
end
myshow (generic function with 1 method)
julia> myeval(x) = Main.eval(Meta.parse(x))
myeval (generic function with 1 method)
#Round-tripping works for Vector
julia> x = collect(1:4)
4-element Vector{Int64}:
1
2
3
4
julia> myshow(x)
"[1, 2, 3, 4]"
julia> myeval(myshow(x)) == x
true
#Round-tripping works for 2-d array with 2 columns
julia> y = fill(1,(2,2))
2×2 Matrix{Int64}:
1 1
1 1
julia> myeval(myshow(y)) == y
true
#Round-tripping fails for 2-d array with 1 column
julia> z = fill(1,(3,1))
3×1 Matrix{Int64}:
1
1
1
julia> myshow(z)
"[1; 1; 1]"
julia> myeval(myshow(z))
3-element Vector{Int64}:
1
1
1
julia> myeval(myshow(z)) == z
false