Print vector

How does one get @show to print the vector as it is shown in the REPL, that is vertically?

display(a)

Right, but that is not @show

then the answer is no you can’t

If you don’t mind pirating Base.show(::String):

julia> @macroexpand @show a
quote
    Base.println("a = ", Base.repr(begin
                #= show.jl:1128 =#
                local var"#3#value" = a
            end))
    var"#3#value"
end

julia> repr(a)
"[1, 2, 3]"

julia> show(a)
[1, 2, 3]
julia> display(a)
3-element Vector{Int64}:
 1
 2
 3

julia> show(s::String) = display(s)
ERROR: error in method definition: function Base.show must be explicitly imported to be extended
Stacktrace:
 [1] top-level scope
   @ none:0
 [2] top-level scope
   @ REPL[12]:1

julia> import Base.show

julia> show(s::String) = display(s)
show (generic function with 272 methods)

julia> @show a
a = [1, 2, 3]
3-element Vector{Int64}:
 1
 2
 3
1 Like

That’s this issue: Define macro @display · Issue #15820 · JuliaLang/julia · GitHub (closed but should be reopened I think)

1 Like