I’ve defined the binary “parallel” operator as:
∥(a::Number,b::Number) = 1/(1/a+1/b)
This operation is very common in electronics, and is related to the harmonic mean.
I’ve also overloaded it with ∥(a::Component,b::Component)
to allow the paralleling of a custom data structure I created.
It works very well (although of course I’d prefer to type \par instead of \parallel, but I’ll save that for later)…
julia> 1 ∥ 2
0.6666666666666666
However, if I try cascading it, it doesn’t work so well.
julia> 1 ∥ 2 ∥ 3
TypeError: non-boolean (Float64) used in boolean context
Stacktrace:
[1] top-level scope at In[48]:1
[2] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
I found from this link that the problem is that Julia expects this operator to return a Boolean and performs conditional evaluation.
julia> Meta.@lower 1 ∥ 2 ∥ 3
:($(Expr(:thunk, CodeInfo(
@ none within `top-level scope'
1 ─ %1 = 1 ∥ 2
└── goto #3 if not %1
2 ─ %3 = 2 ∥ 3
└── return %3
3 ─ return false
))))
- Can I disable this Boolean treatment somehow? (Without custom macros)
- How can I set its operator precedence to the same as
+
? (Since ∥ and + share the same arithmetic properties.)
Thanks!