In current nim's user defined operators, users must use the leader char or some special rules to specify Precedence and Associativity. This makes some operators do not like that appropriate. Can nim introduce two pragmas to specify these stuffs for convenience.
Current nim with right associativity:
proc `^|>`(a: auto, b: auto): auto =
a(b)
proc foo(a: int): int =
a
let bar = foo ^|> foo ^|> 123
If we have paragmas, codes should like:
proc `|>`(a: auto, b: auto): auto {.precedence: 0, associativity: right .} =
a(b)
proc foo(a: int): int =
a
let bar = foo |> foo |> 123
I am not a nim developer, but as far as I know user defined precedence and associativity do not work very well with macros.
macro foobar(arg: untyped): stmt =
# bla bla
foobar(foo |> foo |> 123)
now the structure of the ast wich is supposed to be contexd independent, because it is an untyped ast, depends on the context again, in this case the associativity. So to answer your question, I doubt that nim can introduce user defined percedence and associativity.
Yeah, what Krux02 said. That feature wouldn't work well with macros.
For your example you can shorten your operator to ^>.
let bar = foo ^> foo ^> 123
Looks good to me.