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

What is used for value display in REPL? #53678

Closed
aplavin opened this issue Mar 9, 2024 · 4 comments · Fixed by #53926
Closed

What is used for value display in REPL? #53678

aplavin opened this issue Mar 9, 2024 · 4 comments · Fixed by #53926
Labels
display and printing Aesthetics and correctness of printed representations of objects. docs This change adds or pertains to documentation

Comments

@aplavin
Copy link
Contributor

aplavin commented Mar 9, 2024

My original question is "which function is used by the REPL to display values", and I couldn't really find a definite answer.

Docs point to display(x)

julia/doc/src/manual/types.md

Lines 1483 to 1484 in 6f8ba49

where the single-line `show(io, z)` form is still used for an array of `Polar` values. Technically,
the REPL calls `display(z)` to display the result of executing a line, which defaults to `show(stdout, MIME("text/plain"), z)`,

and to show

Objects are printed at the REPL using the [`show`](@ref) function with a specific [`IOContext`](@ref).

on different pages.

But this is definitely not the whole story, the output of display(x) and just x in REPL is different:

julia> using StructArrays, JLArrays  # or any actual GPU array instead of JLArray

julia> x = StructArray(a=JLArray(rand(3)))
3-element StructArray(::JLArray{Float64, 1}) with eltype @NamedTuple{a::Float64}:
 (a = 0.7284120253405527,)
 (a = 0.12606390581511362,)
 (a = 0.6120157378655939,)

julia> x |> display
3-element StructArray(::JLArray{Float64, 1}) with eltype @NamedTuple{a::Float64}:
ERROR: Scalar indexing is disallowed.
...

So, would be nice to document how it actually works... I personally don't understand it for now.

@jariji
Copy link
Contributor

jariji commented Mar 11, 2024

@jishnub jishnub added the docs This change adds or pertains to documentation label Mar 13, 2024
@jakobnissen jakobnissen added the display and printing Aesthetics and correctness of printed representations of objects. label Mar 13, 2024
@stevengj
Copy link
Member

stevengj commented Apr 2, 2024

This is documented in Custom pretty-printing in the manual.

Technically, the REPL calls display(z) to display the result of executing a line, which defaults to show(stdout, MIME("text/plain"), z), which in turn defaults to show(stdout, z)

The REPL calls display, which defaults to the 3-argument show (with an appropriate IOContext — that line of the manual should be fixed to note that the REPL wraps stdout in an IOContext — fixed in #53926), which defaults to the 2-argument show. (print calls the 2-argument show.)

However, GPUArrays.jl does some task-dependent enabling of scalar indexing which makes show behave differently in the REPL display. This is a bit confusing — I wish they used show overloading or the IOContext instead. (But obviously packages can overload these functions in all sorts of ways, and we can't control how closely they follow the Base documentation.)

@stevengj
Copy link
Member

stevengj commented Apr 2, 2024

@jariji, see also #53927.

@stevengj
Copy link
Member

stevengj commented Apr 2, 2024

#53926 fixes the omission of display from the REPL docs, and should close this issue.

fingolfin pushed a commit that referenced this issue May 24, 2024
Fix omission in pretty-printing docs mentioned here:
#53678 (comment)

(I think these docs were written before `IOContext` existed?)

Also fixes a corresponding place in the REPL docs, which mentioned the
`IOContext` but omitted `display`. Closes #53678
lazarusA pushed a commit to lazarusA/julia that referenced this issue Jul 12, 2024
Fix omission in pretty-printing docs mentioned here:
JuliaLang#53678 (comment)

(I think these docs were written before `IOContext` existed?)

Also fixes a corresponding place in the REPL docs, which mentioned the
`IOContext` but omitted `display`. Closes JuliaLang#53678
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. docs This change adds or pertains to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants