The behaviour we see is due to the precedence of &
, which is much lower than the precedence of /@
. As a consequence, the expression Line /@ (Print[#]; #)
is bound tightly together by the high precedence /@
infix operator, yielding the single argument to the low precedence &
postfix operator. This means that the second expression is interpreted as (note the added parentheses prior to the second /@
):
(Line /@ (Print[#]; #) &) /@ {{{2, 1}, {1, 1}}, {{-2, 1}, {3, 1}}}
which is equivalent to:
Map[Line /@ (Print[#]; #) &, {{{2, 1}, {1, 1}}, {{-2, 1}, {3, 1}}}]
or
Map[Map[Line, (Print[#]; #) &], {{{2, 1}, {1, 1}}, {{-2, 1}, {3, 1}}}]
This is manifestly different from the first expression in the question.
One way to see this in the front-end is to place the cursor somewhere within Print
and then extend the selection using CTRL+. repeatedly. With each key press, the selection grows outward to show how subexpressions group together due to precedence. Repeatedly double-, triple-, quadruple-clicking, etc. on a selection point will also extend the selection to show precedence.
Another way to see how the expression is interpreted is to inspect its full-form:
Line /@ (Print[#];#)& /@ {{{2,1},{1,1}},{{-2,1},{3,1}}} // FullForm // HoldForm
(*
Map[
Function[Map[Line, CompoundExpression[Print[Slot[1]],Slot[1]]]],
List[List[List[2,1],List[1,1]],List[List[-2,1],List[3,1]]]]
*)
The Wolfram Language documentation has a section that details operator precedence.
tutorial/OperatorInputForms
, with its listing in order of precedence, help? $\endgroup$