Thank you Yichao, you have been of inestimable help. Everything works up to
one detail (that I do not necessarily need to solve, but just for the
record):
macro operator_obs(name)
nname = symbol("$name")
dname = symbol(".$name")
return quote
function $(esc(nname))(m1::M, m2::M)
return M($(esc(dname))(m1.a, m2.a), $(esc(dname))(m1.b, m2.b))
end
end
end
ol = [+, -, *, /, ^]
for o in ol
@eval @operator_obs($o)
end
That's the final solution, the purpose of nname in the macro is because,
for some obscure reason, Julia complains if I keep using $(esc(name)) as
the function name, although I can use it inside the macro everywhere else.
And it works if I try with dot operators like .+... I do not quite
understand that part to be honest.