I suppose there’s also a hypothetical future in which Julia’s parsing rules change such that numeric literals are callable. Then it’d be trivial to define:
(x::Number)(y::Number) = x*y # for backwards-compatibility
(x::Number)(b::Bool) = b ? x : zero(x) # for indication
In addition to 1(p::Bool)
serving as an indicator, this concept also has the advantage(?) that the product (a+b)(c+d)
would become valid.
Suppose I wish to calculate the sum of non-negative values of xs
. Since indicating is implicit, I might write:
(xs .≥ 0)' * xs
If Bool
identified with infinite values, we’d need an explicit indicator and be forced to write a longer expression such as:
1.(xs .≥ 0)' * xs