# Problem With Nested Pure Functions

GROUPS:
 Frank Kampas 1 Vote Array[Subscript[\[Lambda], #] &, {3}]gives{Subscript[\[Lambda], 1], Subscript[\[Lambda], 2], \Subscript[\[Lambda], 3]}However, if I try to generate two lists with different symbols and different lengths, the best I've come up with itInner[Function[{a, b},   Array[Subscript[a, #] &, b]], {\[Lambda], \[Mu]}, {2, 3}, List]which gives{{Subscript[\[Lambda], 1], Subscript[\[Lambda], 2]}, {Subscript[\[Mu],   1], Subscript[\[Mu], 2], Subscript[\[Mu], 3]}}If I try to change Function to the # & notation, I run into a conflict in the variablesInner[Array[Subscript[#1, #] &, #2] &, {\[Lambda], \[Mu]}, {2,   3}, List]gives{{Subscript[1, 1], Subscript[2, 2]}, {Subscript[1, 1], Subscript[2,   2], Subscript[3, 3]}}Any suggestions?
4 years ago
8 Replies
 Jason Grigsby 1 Vote This is not directly addressing your question, but if I can, I try to avoid nesting pure functions. An example might beInner[Map,{\[Lambda],\[Mu]},Range /@{2, 3},List]/.{a_[n_] -> Subscript[a, n]}Otherwise, it's easy to confuse the meaning of the various # symbols.
4 years ago
 it is perfectly fine to nest anonymous functions. the problem is notational. you should only use the (..)& notation once or else WL gts confused. this is discussed in the WL prpgramming tutorial located at http://library.wolfram.com/infocenter/MathSource/5216/ . this is discussed on pp. 32-34 in the pdf version and p.41 shows a 'triple nested' anonymous function for a Game of Life program.
4 years ago
 Isaac Abraham 1 Vote The following is another option which allows me to pair the symbols and listlength.Clear["`*"];(* Define the function that generates a list-of-lists *)array[{s_,n_}] := Array[Subscript[s,#]&, n](* Call the function as often as needed with {symbol, listlength} pairs *)array[#]& /@ {{ \[Lambda], 3},{\[Kappa], 4},{\[Delta], 5} }
4 years ago
 Frank Kampas 1 Vote Jason, your answer inspired me to tryInner[Map, {Subscript[\[Lambda], #] &, Subscript[\[Mu], #] &}, Range /@ {2, 3}, List]which also works.Thanks
4 years ago
 Frank, that was the one I kept trying to come up with but I had some sort of mental block. I eventually settled on just using replacement. I'm glad you figured it out because I was getting really frustrated with myself. I like the other solutions here too.