Thanks John! I found that the macro I want is `@swappable`.
On Wed, Feb 12, 2014 at 4:35 PM, John Myles White <[email protected]>wrote: > To see a macro that does this sort of thing, look into the code for > DataArrays, specifically src/operators.jl. > > -- John > > On Feb 12, 2014, at 7:39 AM, Cristóvão Duarte Sousa <[email protected]> > wrote: > > > Hi, > > > > I'll put this as an example to better explain myself. > > In complex.jl there are these two lines: > > ==(z::Complex, x::Real) = isreal(z) && real(z) == x > > ==(x::Real, z::Complex) = isreal(z) && real(z) == x > > > > Is there some "standard" macro to apply to definitions of functions > which have the same behavior independently of arguments order? > > Something like a `@withsymm` macro which can be used as > > @withsymm ==(z::Complex, x::Real) = isreal(z) && real(z) == x > > and expands to the two lines above. > > Or even maybe to > > ==(z::Complex, x::Real) = isreal(z) && real(z) == x > > ==(x::Real, z::Complex) = ==(z, x) > > > > If not, have you considered (and maybe discarded) the possibility of > using such macro? > > > >
