Repository: JuliaLang/julia
File: base/show.jl (Julia)

Code before:
                 length(d) == 1 ? "$(d[1])-element" :
                 join(map(string,d), '×')

inds2string(inds) = join(map(_indsstring,inds), '×')
_indsstring(i) = string(i)
_indsstring(i::Union{IdentityUnitRange, Slice}) = string(i.indices)

# anything array-like gets summarized e.g. 10-element Array{Int64,1}
summary(io::IO, a::AbstractArray) = array_summary(io, a, axes(a))
function array_summary(io::IO, a, inds::Tuple{Vararg{OneTo}})
    print(io, dims2string(length.(inds)), " ")
    showarg(io, a, true)
end
function array_summary(io::IO, a, inds)
    print(io, dims2string(length.(inds)), " ")
    showarg(io, a, true)
    print(io, " with indices ", inds2string(inds))
end

"""
    summary(io::IO, ref::GenericMemoryRef)

Print a brief description of a `GenericMemoryRef`, showing the remaining
accessible length from the current offset. This improves error messages
like `BoundsError` to reflect the effective size, similar to `SubString`.
"""
function Base.summary(io::IO, ref::GenericMemoryRef{kind,T,AS}) where {kind,T,AS}
    mem = parent(ref)
    idx = Core.memoryrefoffset(ref)            # 1-based offset within parent memory
    rem = length(mem) - (idx - 1)              # remaining accessible elements
    if rem <= 0
        print(io, "empty ", typeof(ref))
    else
        print(io, rem, "-element ", typeof(ref))
    end
end

## `summary` for Function
summary(io::IO, f::Function) = show(io, MIME"text/plain"(), f)

"""
    Base.showarg(io::IO, x, toplevel)

Show the quasi-type of `x` where quasi-type is the type of `x` or an expression (possibly
containing quasi-types) that would generate an object of the same type as `x`. The shorter
of these two options is typically used.

This function is used by `summary` to display type information in terms of sequences of
function calls on objects.

Show a leading `::` if `toplevel` is `false` and showing a type. `toplevel` is `true` if

Review comment (suggestion):
There's no need to add a docstring for methods that are already documented by the generic function docstring and don't deviate from the generic interface.

```suggestion
```

Code after:
                 length(d) == 1 ? "$(d[1])-element" :
                 join(map(string,d), '×')

inds2string(inds) = join(map(_indsstring,inds), '×')
_indsstring(i) = string(i)
_indsstring(i::Union{IdentityUnitRange, Slice}) = string(i.indices)

# anything array-like gets summarized e.g. 10-element Array{Int64,1}
summary(io::IO, a::AbstractArray) = array_summary(io, a, axes(a))
function array_summary(io::IO, a, inds::Tuple{Vararg{OneTo}})
    print(io, dims2string(length.(inds)), " ")
    showarg(io, a, true)
end
function array_summary(io::IO, a, inds)
    print(io, dims2string(length.(inds)), " ")
    showarg(io, a, true)
    print(io, " with indices ", inds2string(inds))
end

## `summary` for GenericMemoryRef
function summary(io::IO, mref::GenericMemoryRef)
    offset = Core.memoryrefoffset(mref)
    len_after_offset = length(mref.mem) - offset + 1
    print(io, len_after_offset, "-element ")
    showarg(io, mref, true)
end

## `summary` for Function
summary(io::IO, f::Function) = show(io, MIME"text/plain"(), f)

"""
    Base.showarg(io::IO, x, toplevel)

Show the quasi-type of `x` where quasi-type is the type of `x` or an expression (possibly
containing quasi-types) that would generate an object of the same type as `x`. The shorter
of these two options is typically used.

This function is used by `summary` to display type information in terms of sequences of
function calls on objects.

Show a leading `::` if `toplevel` is `false` and showing a type. `toplevel` is `true` if
this is the direct call from `summary` and `false` for nested (recursive) calls.

The fallback definition is to print `x` as "::\\\$(typeof(x))" or "\\\$(typeof(x))",
representing argument `x` in terms of its type. However, you can specialize
this function for specific types to customize printing. This customization is useful for
types that have simple, public constructors and verbose and/or internal types and type
parameters such as `reinterpret`ed arrays or `SubArray`s.

# Examples