0

I'm trying to apply a simple function to the second element of a list:

{#1, #2/5} &@{1, 2}

But this returns an error message.

Function::slotn: "Slot number 2 in {#1,#2/5}& cannot be filled from ({#1,#2/5}&)[{1,2}]."

What is the correct syntax ?

MarcoB
  • 67,153
  • 18
  • 91
  • 189
Whelp
  • 1,715
  • 10
  • 21
  • {#1, #2/5} &[1, 2] or {#1, #2/5} & @@ {1, 2} – garej Feb 28 '16 at 15:38
  • 1
    Also {#1, #2/5} & @@ {1, 2} or {#[[1]], #[[2]]/5} &@{1, 2} – Bob Hanlon Feb 28 '16 at 15:44
  • I see, now it works. – Whelp Feb 28 '16 at 15:55
  • You could also use MapAt[#/5&, {1, 2}, 2] – Mr.Wizard Feb 28 '16 at 16:05
  • Apply[{#1, #2/5} &]@{1, 2} – garej Feb 28 '16 at 16:18
  • @Mr.Wizard This is not a duplicate of "another way to do this mapping of a two argument function". The OP is asking about applying a function to the second argument of a list, i.e. transforming some responses. The supposed duplicate discusses applying a two-argument function to all elements of a list of pairs. – masterxilo Jun 30 '16 at 12:38
  • @masterxilo If I recall my reasoning this question was likely to be closed as "easily found in the documentation" so instead I marked it as a duplicate of a closely related question which has answers that when understood could be applied to solve this one. garej and Bob Hanlon both gave (in comments) solutions that are effectively duplicates (24940) or (24941). As you can see I also tried to answer this specific question in a comment. Do you have a nontrivial answer you wish to post that – Mr.Wizard Jun 30 '16 at 15:38

0 Answers0