How to work with julia's structs

Welcome,

please take a look at PSA: how to quote code with backticks.

Regarding your problem, Constructors · The Julia Language is likely good reading.

You could do for example:

julia> struct Point{T}
           r::T
           theta::T
           phi::T
           x::T
       end

julia> Point(r, theta, phi) = Point(r, theta, phi, r * sin(theta) * cos(phi))
Point

julia> Point(2.0, 0.3, 0.5)
Point{Float64}(2.0, 0.3, 0.5, 0.5186867601044616)
2 Likes