Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

consider this example:

list = {a, b, c};
Table[{Sin[i], Cos[j]}, {i, 1, 3}, {j, list[[i ;;]]}]

(*{{{Sin[1], Cos[a]}, {Sin[1], Cos[b]}, {Sin[1], Cos[c]}}, {{Sin[2], 
   Cos[b]}, {Sin[2], Cos[c]}}, {{Sin[3], Cos[c]}}}*)

for the following code:

{Sin[#], Cos[#]} & /@ list[[# ;;]] & /@ {1, 2, 3}

we can get same result if the slot inside Sin (Sin[#]) takes the values from the outer range ({1,2,3})

so in general, is it possible to specify which range that slot takes from?

share|improve this question
I read this question twice and I still don't understand it. Edit: Okay, thanks to Verbeia's answer I think I understand. I do find the phrasing of the question confusing. – Mr.Wizard Aug 5 '14 at 23:21
@Mr.Wizard, Sorry for not being clear. – Algohi Aug 6 '14 at 0:04
up vote 7 down vote accepted

My first suggestion would be to localize the outer Slot, like this:

With[{indx = #}, {Sin[indx], Cos[#]} & /@ list[[indx ;;]]] & /@  Range[3]

(* {{{Sin[1], Cos[a]}, {Sin[1], Cos[b]}, {Sin[1], Cos[c]}}, {{Sin[2], 
   Cos[b]}, {Sin[2], Cos[c]}}, {{Sin[3], Cos[c]}}} *)

You could also rework the process to get the full set of tuples of {Sin[1],Sin[2],Sin[3]} and {Cos[a],Cos[b],Cos[c]} and keep the ones you want, using something like:

MapThread[#1[[#2 ;;]] &, {Outer[{Sin[#1], Cos[#2]} &, Range[3], list],
share|improve this answer

You can nest Functions to accomplish what I believe you want to:

f = i \[Function] {Sin[i], Cos[#]} & /@ list[[i ;;]];

Array[f, 3] // Column

This looks nicer in the Notebook:

enter image description here

Other methods include:

# /. i_ :> ({Sin[i], Cos[#]} & /@ list[[i ;;]]) & /@ {1, 2, 3}

With[{i = #}, {Sin[i], Cos[#]} & /@ list[[i ;;]]] & /@ {1, 2, 3}  (* Verbeia's *)

Nevertheless I feel that the Table construct is at least as clear as any of these.

share|improve this answer

is it possible to specify which range that slot takes from?

The short answer is "no" (not counting solutions with named arguments since they aren't Slots) but if you really, really want to do it you can write it like I've done below, then #1 refers to the inner Map and #2 refers to the outer Map:

   {Sin[#], Cos[#2]} & @@ # &,
   Thread@{#, list[[# ;;]]}
   ] &,
 {1, 2, 3}

This technique can be used for more levels I think, so that if you had four Map inside each other you could use #1, #2, #3 and #4 to refer to the different levels. But it isn't worth the trouble to start thinking about it.

share|improve this answer
Nice. consider this also, {Sin[#1], Cos[#2]} & @@@ Thread[{#, list[[# ;;]]}] & /@ Range[3] – Algohi Aug 6 '14 at 0:50
@Algohi Yep, that works too. – C. E. Aug 6 '14 at 0:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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