-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
This has been discussed multiple times on Slack and Discord, but I want to file an issue here so it can be formally tracked.
Something I would really like in Julia is "backwards looking macros", broadly similar to R's %>% operator magic. But don't worry, this is not yet another piping thread.
I really like Chain.jl and use it all the time. ie. @chain x f1(a) f2(b) becomes f2(f1(x, a), b). The only problem is that it's hard to work with interactively. Often times I write x first and then only later realize I need to do something to it. In R, a frequent pattern I have is
R> f(a, b, c, df %>% filter(x == 1))
where the last filter is added because I realized I only wanted to consider observations where x == 1 in the operation. But I realized this after I had already been typing.
I recognize there is InfixFunctions.jl , but it lacks the same flexibility as metaprogramming.
I do not know how complicated this would be to implement. But my preferred syntax would be something along the lines of
backwards macro xx(args...)
...
end
which is exactly like a normal macro, but it captures the preceding element. as well. In this way
y @_xx_backwards a b c
behaves exactly the same as
@xx(y, a, b, c)
Thank you!