# ‘show’ function for user-defined struct

**URL:** <https://discourse.julialang.org/t/show-function-for-user-defined-struct/107391>\
**Category:** General Usage\
**Tags:** question\
**Created:** [December 10, 2023, 11:01pm UTC](https://discourse.julialang.org/t/show-function-for-user-defined-struct/107391 "2023-12-10T23:01:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiang\_ming\_zhang](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jiang_ming_zhang/32/204063_2.png) [@jiang\_ming\_zhang](https://discourse.julialang.org/u/jiang_ming_zhang)\
**Post date:** [December 10, 2023, 11:01pm UTC](https://discourse.julialang.org/t/show-function-for-user-defined-struct/107391/1 "2023-12-10T23:01:43Z")

</div>

```julia
julia> struct my
       age :: Int
       weight :: Float64
       end

julia> function Base.show(io::IO, h::my)
       print(io,"my struct")
       end

```

Here I defined a struct and a new method for the function ‘show’. Then when I instantiate a variable

```julia
julia> a = my(34,45.0)
my struct

```

the function ‘show’ is invoked automatically. I did not call it. What is the mechanism behind?

---

<div class="post-metadata">

**Author:** ![chiion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chiion/32/37002_2.png) [@chiion](https://discourse.julialang.org/u/chiion)\
**Post date:** [December 11, 2023, 12:14am UTC](https://discourse.julialang.org/t/show-function-for-user-defined-struct/107391/2 "2023-12-11T00:14:56Z")

</div>

That’s just standard REPL behavior. When you evaluate an expression in REPL (without semicolon) the result is automatically printed on screen. The result is printed by REPL using the `Base.show` function automatically. See [the doc](https://docs.julialang.org/en/v1/stdlib/REPL/#The-different-prompt-modes) here for more detail.
