Skip to content
Prev 61574 / 63421 Next

Generalised piping into operators

On 21/04/2023 12:16 p.m., Michael Milton wrote:
I thought the decision to exclude "_ + 1" happens after enough parsing 
has happened so that the code making the decision can't tell the 
difference between "_ + 1" and "`+`(_, 1)".  I might be wrong about 
that, but this suggests it:

   > quote(_ + 1)
   Error in quote("_" + 1) : invalid use of pipe placeholder (<input>:1:0)
   > quote(`+`(_,  1))
   Error in quote("_" + 1) : invalid use of pipe placeholder (<input>:1:0)

On the other hand, this works:

   > quote(x |> `+`(e1 = _, 1))
   x + 1

So maybe `+`() is fine after all.

Duncan Murdoch