0

I'm having trouble deciphering why the following couple of expressions evaluate the way they do.

#&@@

This returns the first value of a list. Why? Naïvely I would have expected this to replace the head of the list with the list itself.

1 ## &@@

This multiplies a list together, like

Times@@

Why is that? I imagine it's for the same reason as the first shortcut.

A Simmons
  • 412
  • 4
  • 9
  • 4
    Take a look there and at linked ref pages: What the @#%^&*?! – Kuba Jan 29 '16 at 17:38
  • 2
    It does not strictly "return the first value of a list": it just returns the first argument to the function following @@, for lists, the full form is List[x,y,z], and the 1st argument is x, which is also the first value of a list. Try # & @@ func[c, b, a] – egwene sedai Jan 29 '16 at 17:45
  • You can also try to translate short-form expressions by wrapping them in FullForm[Hold[...]]. That displays the long form from which you can go to the help pages more easily. – Jens Jan 29 '16 at 17:51

1 Answers1

3
#&@@list === First@list

because #===#1(first argument), try #2&@@{7,6,5,4}

In the second case 1 x means Times[1,x] so the expression

1 ## &@@{5,4,3,2} === Times[1,Sequence[5,4,3,2]] == Times[1,5,4,3,1]
JJM
  • 905
  • 4
  • 10