This is a ātechniqueā Iāve seen used in some library function to override a group of functions.
import Base.*, Base.+,Base.-,Base./
struct X
a::Float64
b::Float64
c::Float64
end
X(x::Vector)=X(x...)
((;a,b,c)::X)() = [a,b,c]
julia> for o in (:*,:+,:-,:/)
@eval $o(y::Number,x::X) = ($o).(y, x()) |> X
@eval $o(x::X,y::Number) = ($o).(x(), y) |> X
end
julia> X(12,24,30)/3
X(4.0, 8.0, 10.0)
julia> 1/3*X(12,24,30)
X(4.0, 8.0, 10.0)
julia> X(1,2,3)-3
X(-2.0, -1.0, 0.0)
julia> -3+ X(1,2,3)
X(-2.0, -1.0, 0.0)
julia> 10 - X(1,2,3)
X(9.0, 8.0, 7.0)
The main reason for my post (rather than suggesting an alternative solution to those already provided) is to ask for enlightenment on the logic of the expression ((;a,b,c)::X)() = [a,b,c]
I understand how it is used operationally but I would like to understand the meaning of the syntax (starting from the use of the ā;ā) . Is it a function? what kind of function? or what else is it?