# \`show\` versus \`parse\` and arrays with 2 dimensions but only one column

**URL:** https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142
**Category:** General Usage
**Created:** [October 21, 2021, 10:43am UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142 "2021-10-21T10:43:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![PGS62](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pgs62/32/207030_2.png) [@PGS62](https://discourse.julialang.org/u/PGS62)
#### Post date: [October 21, 2021, 10:43am UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142/1 "2021-10-21T10:43:40Z")

</div>

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
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

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [October 21, 2021, 11:00am UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142/2 "2021-10-21T11:00:31Z")

</div>

To crosspost from slack:

The function `myshow` is called `repr`:

```julia
julia> a = [1; 2;;]
2×1 Matrix{Int64}:
 1
 2

julia> repr(a)
"[1; 2;;]"

julia> eval(Meta.parse(repr(a))) == a
true

```

---

<div class="post-metadata">

### Author: ![PGS62](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pgs62/32/207030_2.png) [@PGS62](https://discourse.julialang.org/u/PGS62)
#### Post date: [October 21, 2021, 11:42am UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142/3 "2021-10-21T11:42:10Z")

</div>

Strangely enough that does not work for me:

```julia
julia> a = [1; 2;;]
2-element Vector{Int64}:
 1
 2

julia> versioninfo()
Julia Version 1.6.3
Commit ae8452a9e0 (2021-09-23 17:34 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-11.0.1 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 8
  JULIA_EDITOR = code

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [October 21, 2021, 11:52am UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142/4 "2021-10-21T11:52:53Z")

</div>

Ah, that may be because I’m on a more recent branch - basically just a few days old version - of julia. You can try the 1.7 release candidate and check if it’s fixed there already (should be, they haven’t diverged much yet).

---

<div class="post-metadata">

### Author: ![yha](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yha/32/3502_2.png) [@yha](https://discourse.julialang.org/u/yha)
#### Post date: [October 21, 2021, 12:16pm UTC](https://discourse.julialang.org/t/show-versus-parse-and-arrays-with-2-dimensions-but-only-one-column/70142/5 "2021-10-21T12:16:31Z")

</div>

As a side note, the pattern you used in `myshow` of constructing an `IOBuffer`, writing to it and converting to string, is already implemented in the standard function `sprint`:

```julia
julia> x = collect(1:4)
4-element Vector{Int64}:
 1
 2
 3
 4

julia> sprint(show, x)
"[1, 2, 3, 4]"

```
