Skip to content

Commit 3dd07fd

Browse files
authored
document that print(x) and repr(x) call 2-arg show (#53927)
As mentioned [here](https://discourse.julialang.org/t/improving-doc-for-display-print-show-repr/69124/4), the `print(x)` and `repr(x)` docstrings say that they default to calling `show`, but don't specifically say that they call the 2-argument `show`. (Probably because they pre-date the 3-argument `show`).
1 parent 7ba1b33 commit 3dd07fd

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

base/strings/io.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ if `io` is not given) a canonical (un-decorated) text representation.
1010
The representation used by `print` includes minimal formatting and tries to
1111
avoid Julia-specific details.
1212
13-
`print` falls back to calling `show`, so most types should just define
14-
`show`. Define `print` if your type has a separate "plain" representation.
15-
For example, `show` displays strings with quotes, and `print` displays strings
16-
without quotes.
13+
`print` falls back to calling the 2-argument `show(io, x)` for each argument `x` in `xs`,
14+
so most types should just define `show`. Define `print` if your type has a separate
15+
"plain" representation. For example, `show` displays strings with quotes, and `print`
16+
displays strings without quotes.
1717
1818
See also [`println`](@ref), [`string`](@ref), [`printstyled`](@ref).
1919
@@ -252,8 +252,8 @@ print(io::IO, s::Union{String,SubString{String}}) = (write(io, s); nothing)
252252
"""
253253
repr(x; context=nothing)
254254
255-
Create a string from any value using the [`show`](@ref) function.
256-
You should not add methods to `repr`; define a `show` method instead.
255+
Create a string from any value using the 2-argument `show(io, x)` function.
256+
You should not add methods to `repr`; define a [`show`](@ref) method instead.
257257
258258
The optional keyword argument `context` can be set to a `:key=>value` pair, a
259259
tuple of `:key=>value` pairs, or an `IO` or [`IOContext`](@ref) object whose
@@ -262,7 +262,7 @@ attributes are used for the I/O stream passed to `show`.
262262
Note that `repr(x)` is usually similar to how the value of `x` would
263263
be entered in Julia. See also [`repr(MIME("text/plain"), x)`](@ref) to instead
264264
return a "pretty-printed" version of `x` designed more for human consumption,
265-
equivalent to the REPL display of `x`.
265+
equivalent to the REPL display of `x`, using the 3-argument `show(io, mime, x)`.
266266
267267
!!! compat "Julia 1.7"
268268
Passing a tuple to keyword `context` requires Julia 1.7 or later.

0 commit comments

Comments
 (0)