1

I am interested in executing the following command but don't know the proper syntax to distinguish between nested arguments, here at the Select and Map levels. For example,

Map[Select[secondList, StringMatchQ[myFunction[#], #] &] &, firstList]

where myFunction is being applied to the elements in secondList and the second # is using the element passed to Select from Map (i.e. members of firstList).

Unfortunately, I don't have a solid enough understanding of Mathematica to figure out the correct syntax. Can anyone help me do this?

corey979
  • 23,947
  • 7
  • 58
  • 101
mikemtnbikes
  • 679
  • 3
  • 11
  • 9
    You can use the full Function form with named arguments to disambiguate things. – Sjoerd C. de Vries May 28 '15 at 21:07
  • I thought of that, but was hoping to avoid defining a separate function (which given my poor programming skills would be defined outside of Map[], so if you can do it w/in Map[], I'd love to see it. I appreciate the keyword 'disambiguation' and am wondering if there are any other ways to do it. Thanks @SjoerdC.deVries. – mikemtnbikes May 29 '15 at 17:55
  • Don't confuse the function Function with a function in general. Please read the linked documentation and you'll see that you can use it directly within Map. – Sjoerd C. de Vries May 29 '15 at 17:58
  • @Xavier I disagree that this is a duplicate. The linked question is about precedence and is fixed by a pair of brackets. Here references to the arguments of the outer function need to be within the inner function and no amount of brackets can help with that. – LLlAMnYP Sep 15 '16 at 16:57
  • @LLlAMnYP You are right, sorry for overlooking. I will retract my closing vote. I was searching for a duplicate as I am pretty sure this inner / outer slot issue was mentioned and answered somewhere else. Does it ring you any bell? I'll continue searching. –  Sep 15 '16 at 17:41
  • @LLlAMnYP This is better. –  Sep 15 '16 at 17:44
  • @Xavier I agree – LLlAMnYP Sep 15 '16 at 20:01

1 Answers1

2

The Map statement can be rewritten as such:

Map[
  Function[{elementOfFirstList},
    Select[secondList,
      Function[{elementOfSecondList},
        StringMatchQ[myFunction[elementOfSecondList], elementOfFirstList]
      ]
    ]
  ],
  firstList]
LLlAMnYP
  • 11,486
  • 26
  • 65