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
Which instead yields:
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.
@has a very high precedence. The issue is with precedences. Shouldx OP1 y OP2 zbe interpreted as(x OP1 y) OP2 zorx OP1 (y OP2 z)? In Mathematica it's the latter only ifOP2has a higher precedence thanOP1. – Szabolcs May 25 '15 at 20:30f @ (g @@ x)you might want to usef @ Apply[g] @ x, which is more verbose, but does save parentheses. Unfortunately when you use pure functions (...¬ation), 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:33f @ Apply[g] @ xdoes the trick. Thanks for your help. – Bichoy May 25 '15 at 20:38Grid@Flatten[#, 1] &@{{#}, # /. lst1} &@{a, b}– Bob Hanlon Jun 04 '15 at 17:10