As we know, Julia’s functions can modify the contents of the passed mutable struct or Array. Sometimes this can cause confusion as to whether the function modifies the members of the mutable struct or not. It might be helpful to write a detailed document.
You can help yourself much by adding a doc string.
Minimal working example:
mutable struct TypeA
n::Int
end
mutable struct TypeB
x::Float64
end
"""
`fun!(a::TypeA, b::TypeB, c::AbstractVector{Float64})` only mutates `b`.
"""
function fun!(a::TypeA, b::TypeB, c::AbstractVector{Float64})
b.x = sum(c) / a.n
end
a, b, c = TypeA(10), TypeB(0.0), collect(1.0:10.0)
fun!(a, b, c)
@show a b c;
a = TypeA(10)
b = TypeB(5.5)
c = [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
@doc fun!
fun!(a::TypeA, b::TypeB, c::AbstractVector{Float64}) only mutates b.
julia> ?
help?> fun!
search: fun! function Function functionloc @functionloc @cfunction fullname
fun!(a::TypeA, b::TypeB, c::AbstractVector{Float64}) only mutates b.