Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve show to handle ; in a tuple #32775

Closed
vtjnash opened this issue Aug 3, 2019 · 3 comments · Fixed by #34038
Closed

improve show to handle ; in a tuple #32775

vtjnash opened this issue Aug 3, 2019 · 3 comments · Fixed by #34038
Assignees
Labels
display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests good first issue Indicates a good issue for first-time contributors to Julia

Comments

@vtjnash
Copy link
Member

vtjnash commented Aug 3, 2019

julia> ( :((a,; b)) ) # :/ would be nice for this to round-trip through `show`
:(($(Expr(:parameters, :b)), a))

julia> :( g(a,; b) ) # should print like this, using the same code as handles `:call`:
:(g(a; b))
@vtjnash vtjnash added good first issue Indicates a good issue for first-time contributors to Julia display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests labels Aug 3, 2019
@mrandri19
Copy link

I'd like to take a stab at this, I should be looking in base/show.jl right?

@JeffBezanson
Copy link
Member

Thanks, yes that's correct.

@mrandri19
Copy link

Ok so I've done some more research:

julia> :(1,;2)
:(($(Expr(:parameters, 2)), 1))

The call stack look like this:

  • show_unquoted_quote_expr prints :(
    • show_unquoted prints (
      • show_list
        • show_unquoted prints $(Expr(
          • show prints :parameters
          • show prints , 2
julia> :(f(1,;2))
:(f(1; 2))

The call stack look like this:

  • show_unquoted_quote_expr prints :(
    • show_unquoted
      • show_call prints f(
        • show_list prints 1;
        • show_list prints 2

Now, inside show_call there is some logic to print parameter lists:

if !isempty(func_args) && isa(func_args[1], Expr) && func_args[1].head === :parameters
    print(io, op)
    show_list(io, func_args[2:end], ", ", indent)
    print(io, "; ")
    show_list(io, func_args[1].args, ", ", indent)
    print(io, cl)
else
    show_enclosed_list(io, op, func_args, ", ", cl, indent)
end

while in show_unquoted there is not, therefore it falls back to the default case

if unhandled
    print(io, "\$(Expr(")
    show(io, ex.head)
    for arg in args
        print(io, ", ")
        show(io, arg)
    end
    print(io, "))")
end

Should I just add one more elseif case to show_unquoted, copying the code from show_call?
Or should I add the elseif but extracting the show_call code into a function and using the same in both?
Or should I add the elseif and then change show_call to use show_unquoted instead of its custom logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
display and printing Aesthetics and correctness of printed representations of objects. feature Indicates new feature / enhancement requests good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
3 participants