4
$\begingroup$

If I want to use slots corresponding to different function, how can I dod that. For example:

 Scan[MapIndexed[(#1+#2)*#3&,{"a","b","c"}],Range[5]]

where I want #3 corresponds to elements in Range[5], but obviously it gives me errors. How can I pass #3 to the next function

$\endgroup$
4
$\begingroup$

You can use the alternative form of anonymous functions with named parameters:

Scan[Function[{x}, MapIndexed[Print[(#1 + #2) x] &, {"a", "b", "c"}]], Range[5]]

The old question of mine, Using several anonymous functions mixed together, comes to mind. It also deals with this issue, although in a different context.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.