# Mutating function parameters

**URL:** <https://discourse.julialang.org/t/mutating-function-parameters/108268>\
**Category:** New to Julia\
**Created:** [January 2, 2024, 5:13pm UTC](https://discourse.julialang.org/t/mutating-function-parameters/108268 "2024-01-02T17:13:03Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [January 2, 2024, 5:41pm UTC](https://discourse.julialang.org/t/mutating-function-parameters/108268/3 "2024-01-02T17:41:34Z")

</div>

> [@TimG](#):
>
> Can I cause simple parameters to mutate in the same way as arrays or is this not possible. (I realise I could simply return the changed value).

Take a look at the `Ref` type ([C Interface · The Julia Language](https://docs.julialang.org/en/v1/base/c/#Core.Ref) these docs appear a bit cryptic on first read, a better mental model is given by [What is Ref? - #14 by Oscar\_Smith](https://discourse.julialang.org/t/what-is-ref/47610/14)). You can use it like

```julia
using DataFrames

function doit!(flag::Ref, df)
    if flag[]==true
        flag[]=false
    end
    if df[1, :flag]==true
        df[1, :flag]=false
    end
    println("Within doit, flag=",flag[],", df=",df[1, :flag])
end

function main()
    df = DataFrame(flag = [true])
    flag[]=true
    for i = 1:2
        println("$i - Before, flag=", flag[], ", df=", df[1, :flag])
        doit!(flag, df)
        println("$i - After, flag=", flag[], ", df=", df[1, :flag])
    end
end

main()

```

---

_[View the full topic](https://discourse.julialang.org/t/mutating-function-parameters/108268)._
