2 ms·
Multiple dispatch languages like Julia handle that example fairly easily: +(x::Real, z::Complex) = Complex(x + real(z), imag(z)) +(z::Complex, x::Real) = Comp
by ddragon 8y ago
Multiple dispatch languages like Julia handle that example fairly easily:
+(x::Real, z::Complex) = Complex(x + real(z), imag(z))
+(z::Complex, x::Real) = Complex(x + real(z), imag(z))
And you can call it in both infix or prefix forms. Though Julia is a math focused language and the community tries to stay consistent with the correct notation. You can't add an element to a list using the "+" operator, but you can add each element of two lists if their dimensions match.