How can I create a list of variables of simple functions with arguments? These functions will be defined by the user, to be manipulated with some code later.


I want the lists to be:

(* {x1, x2, x3} *)
(* {y1, y2} *)
(* {z1, z2, z3, z4} *)
  • $\begingroup$ There could be a lot of bullet-proofing needed here. What if the user "accidentally" defines f1[x1_, x2_] := x1 * x2 in addition to the three-argument definition you give? What response would you want? $\endgroup$ – Michael E2 Sep 30 '15 at 12:42
  • $\begingroup$ I agree. Actually, the goal is just do a function to create a list of variables, so it is not necessary to do it by hand. I (user) define the functions and MMA create the lists... of course, junk in, junk out .... $\endgroup$ – LeoRon7 Sep 30 '15 at 13:13
In[4]:= ReleaseHold[List @@@ # & /@ Part[DownValues /@ {f1, f2, f3}, All, 1, 1, {1}]] /. Pattern -> (# &)

Out[4]= {{x1, x2, x3}, {y1, y2}, {z1, z2, z3, z4}}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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