showcompact

showcompact(x)

Show a more compact representation of a value. This is used for printing array elements. If a new type has a different compact representation, it should overload showcompact(io, x) where the first argument is a stream.

Examples

  1. Print compact representation of an array:

    julia> arr = [1, 2, 3, 4, 5];
    julia> showcompact(arr)
    [1, 2, 3, 4, 5]

    This example shows the compact representation of the array arr.

  2. Print compact representation of a nested array:

    julia> nested_arr = [[1, 2], [3, 4], [5, 6]];
    julia> showcompact(nested_arr)
    [[1, 2], [3, 4], [5, 6]]

    It demonstrates the compact representation of a nested array.

  3. Print compact representation of a custom type:
    julia> struct Person
              name::String
              age::Int
          end
    julia> p = Person("Alice", 30);
    julia> showcompact(p)
    Person("Alice", 30)

    In this example, a custom type Person is defined, and showcompact is used to print a compact representation of an instance of that type.

Common mistake example:

julia> val = 10;
julia> showcompact(val)
ERROR: MethodError: no method matching showcompact(::Int64)

In this example, the showcompact function is called with an argument of type Int64. However, showcompact does not have a method defined for Int64. It's important to ensure that the argument passed to showcompact is of a type for which there is an appropriate method defined.

See Also

:@printf, :@sprintf, display, displayable, dump, info, isprint, print, println, print_escaped, print_joined, print_shortest, print_unescaped, print_with_color, pushdisplay, redisplay, show, showall, showcompact, sprint, versioninfo,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: