I keep losing my reference on how to redefine say the || ("or") or && ("and") binary operators. I read somewhere that one has to first do importall Base . Then I tried
Base.||( x::MyType, y::MyType ) = dosomething( x, y )
and also
Base.or( x::MyType, y::MyType ) = dosomething( x, y )
But none of these worked. I would appreciate if somebody could give a reference explaining the basics of how to do this... I was unable to find one with queries such as "redefine binary operator in Julia"...
As && and || are short circuit operations, they can't be overloaded, without adding a special construction separate from functions. To call a function, you need to evaluate all the arguments, and that would not be a short circuit evaluation.
You might be able to overload & and | instead, but it is hard to tell without an example use case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With