Piping and broadcasting

I was trying the pipe symbol and I noticed a quirk that probably makes sense with the precedence rules but it leaves something to be desired in expressiveness:

julia> (1,2,3) .|> -
(-1, -2, -3)
julia> (1,2,3) .|> sin .|> -
(-0.8414709848078965, -0.9092974268256817, -0.1411200080598672)
julia> (1,2,3) .|> - .|> sin
ERROR: syntax: ".|>" is not a unary operator
Stacktrace:
 [1] top-level scope
   @ none:1

julia> ((1,2,3) .|> - ) .|> sin
(-0.8414709848078965, -0.9092974268256817, -0.1411200080598672)

I guess its because the result of a unary operation cannot be resolved when there is another operator that follows it. Is this something that needs attention or should the programmer just be aware of the anomalous behavior?

I feel that the parser should be able to handle this pairwise from the left, though.

Kumar

You’re looking for this:

julia> (1,2,3) .|> (-) .|> sin
(-0.8414709848078965, -0.9092974268256817, -0.1411200080598672)

Since - is a binary operator, using it infix in a pipe in this way requires parentheses.

1 Like