Create named array in Julia

Hello,
I am generating an array with some numeric parameters that then I pass to a function as:

parms = [1,2,3,4,5]
function x!(pt)
    μ, κ, δ, ω, η = p
    return( ((μ+κ)*(δ+ω))^(1/η) )
end
x(parms)

It would be useful to address the single parameters by name, so that I can have flexibility in the definition of the function. That is: I don’t have to put the arguments in the same order as the function’s structure. This is equivalent to R’s

parms <- c(kappa=2, mu=1, delta=3, eta=5, omega=4)
x <- function(p) {
  m = p["mu"]
  k = p["kappa"]
  d = p["delta"]
  o = p["omega"]
  e = p["eta"]
  return( ((m+k)*(d+o))^(1/e) )
}
x(parms)

I have seen some people use TOML but I think it is an overkill and generates files .tomls that break the Julia environment.
Thanks

Checking out Named Tuples.

1 Like

Yep, you’re right. From your solution I have found a post:

# Creating a NamedTuple with similar values
tupl2 = (a = 1, b = 2, c = 4, d = 5)
# Accessing using Index value
println(tupl2[2])
# Accessing using assigned value name
println(tupl3[:b])

Even more conveniently, you can access like this: tupl3.b.

1 Like