# Behaviour of Ref?

**URL:** https://discourse.julialang.org/t/behaviour-of-ref/115321
**Category:** New to Julia
**Tags:** pycall, python
**Created:** [June 7, 2024, 11:33am UTC](https://discourse.julialang.org/t/behaviour-of-ref/115321 "2024-06-07T11:33:44Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![ericphanson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ericphanson/32/215186_2.png) [@ericphanson](https://discourse.julialang.org/u/ericphanson)
#### Post date: [June 7, 2024, 12:08pm UTC](https://discourse.julialang.org/t/behaviour-of-ref/115321/2 "2024-06-07T12:08:19Z")

</div>

Yes, this behavior is expected. Two keywords to look into are _mutation_ and _assignment_ (see for example [Assignment and mutation - #4 by StefanKarpinski](https://discourse.julialang.org/t/assignment-and-mutation/19119/4)).

I will add comments to describe:

```julia
julia> a = 5 # assign the name `a` to point to the value 5
5

julia> typeof(a)
Int64

julia> b = Ref(a) # assign the name `b` to the value `Ref(a)` which is the exact same thing as `Ref(5)`
Base.RefValue{Int64}(5)

julia> typeof(b)
Base.RefValue{Int64}

julia> b[] = 10 # mutate the contents of `b` to be 10, i.e. perform `setindex!(b, 10)`. 
10

julia> b # observe `b` with its updated contents
Base.RefValue{Int64}(10)

julia> a # the name `a` points to the same, unmutated value, 5, since that value has never been touched
5

```

Note that `Ref`s are like any other container; they contain values, and you can change their contents by mutating them.

---

_[View the full topic](https://discourse.julialang.org/t/behaviour-of-ref/115321)._
