# How to force evaluation on the right of an @ operator?

Is there a way to force evaluation on the right before the Prefix operator (@) without using parentheses? I came across this question when I was working with the following example:

I have a list of substitutions like this:

lst1 = {{a -> 1 , b -> 2}, {a -> 3, b -> 4}, {a -> 5, b -> 6}}


I am trying to put it in a grid form, to look like this:

a  b
1  2
3  4
5  6


I get this code working:

Grid @ (Join @@ { Keys @ Take[#, 1], Values @ # } & @ lst1 )


However, it only works with the parenthese ( ) around the Join expression. Is there a way in Mathematica to force everything on the right of an @ to get evaluated first?

I wish I can right something like:

Grid @ Join @@ { Keys @ Take[#, 1], Values @ # } & @ lst1


Grid[Join][{{a, b}}, {{1, 2}, {3, 4}, {5, 6}}]


The reason I am trying to do that, is basically, when I get to apply many functions in this way, it becomes cumbersome to always have to close the parentheses at the end (which defeats my purpose of using the @ operator in the first place). I am mostly looking for an equivalent to the \$ operator in Haskell, if such thing exists.

• Thanks @Szabolcs for your comment, I fixed my question to refer to @ as Prefix operator (my mistake). ... Thanks for your answer, it is sad to hear there isn't such a thing. – Bichoy May 25 '15 at 20:29
• No, there isn't, because @ has a very high precedence. The issue is with precedences. Should x OP1 y OP2 z be interpreted as (x OP1 y) OP2 z or x OP1 (y OP2 z)? In Mathematica it's the latter only if OP2 has a higher precedence than OP1. – Szabolcs May 25 '15 at 20:30
• Instead of f @ (g @@ x) you might want to use f @ Apply[g] @ x, which is more verbose, but does save parentheses. Unfortunately when you use pure functions (...& notation), very often it's still necessary to use parens because & has a low precedence and tends to "eat" everything preceding it. – Szabolcs May 25 '15 at 20:33
• Thanks @Szabolcs for the explanation, indeed f @ Apply[g] @ x does the trick. Thanks for your help. – Bichoy May 25 '15 at 20:38
• Using only prefix operators: Grid@Flatten[#, 1] &@{{#}, # /. lst1} &@{a, b} – Bob Hanlon Jun 4 '15 at 17:10

Instead of f @ (g @@ x) you can use f @ Apply[g] @ x (since Mathematica 10). This is more verbose, but it saves parentheses. Since visually matching parentheses is hard, I think that the latter variant is more readable, especially when there's a long chain of functions.

This style can be used with postfix too (x // Apply[g] // f) and it makes it easy to add or remove functions at any position in the chain without having to worry about precedences.

Most important operators, such as Map, Apply, Replace, etc. support this style.

• Similarly f @* g @@ x works, too. – Michael E2 May 25 '15 at 20:54
• @MichaelE2 Can you elaborate more on that? What does @* mean in this case? (I like this more ... ) – Bichoy May 25 '15 at 21:00
• @Bichoy It is short for Composition. You can search this answer for @* and other such forms. – Michael E2 May 25 '15 at 22:51
• Thanks @MichaelE2, this is indeed a marvelous answer :) Thanks a lot for your help. – Bichoy May 25 '15 at 23:00

As suggested by @MichaelE2 in the comments, I ended up using the composition operator @*. My final code looks like:

Grid @* Join @@ {Keys@Take[#, 1], Values@#}& @ lst1

Grid[Join[
Transpose[Union /@ GatherBy[Flatten[lst1], First][[All, All, 1]]],
Transpose[Union /@ GatherBy[Flatten[lst1], First][[All, All, 2]]]]]


which of course can be streamlined...

• Sorry David, I am mostly asking about the Prefix operator @ and evaluation precedence. I am sorry if my question in its current form isn't clear enough. – Bichoy May 25 '15 at 20:47