Best practice for storing, passing, and managing parameters in economic models

Probably you meant:

@with_kw struct Params
  x::Vector{Float64} = [0.5]
end

I agree that having one value in an immutable struct that must be mutable lacks a beautiful syntax. I have even asked that here before: Mutable scalar in immutable object: the best alternative?

In the cases I needed that I finally keep using a vector with a single element.

None of the alternatives is completely clean, IMO. To have a clean syntax use a mutable struct,

julia> @with_kw mutable struct Params
         α::Float64 = 1.0
       end
Params

julia> a = Params()
Params
  α: Float64 1.0


julia> a.α = 2.0
2.0

julia> a
Params
  α: Float64 2.0

But that may have its performance penalties.

(now I see that a great part of this was already mentioned before)

1 Like