1
|
18866 Views
|
9 Replies
|
8 Total Likes
View groups...
Share
GROUPS:

# Problem With Nested Pure Functions

Posted 11 years ago
 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?
9 Replies
Sort By:
Posted 11 years ago
Posted 11 years ago
 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.
Posted 11 years ago
 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} }
Posted 11 years ago
 Jason, your answer inspired me to tryInner[Map, {Subscript[\[Lambda], #] &, Subscript[\[Mu], #] &}, Range /@ {2, 3}, List]which also works.Thanks
Posted 11 years ago
 Thanks to everyone who replied to my question.  I'm impressed by the answers.
Posted 11 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.
Posted 11 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.
Posted 11 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.
Posted 4 years ago
 Hi Rich,I have been looking for something like this! THANK YOU!!!!!!!!!!!!!