How to extract all necessarily code for a function?

Many times when someone pastes a piece of code into SE there are missing values and symbols that the user left out.

To prevent this I’m looking for a function that uproots other functions (extract the roots of the function like pulling a plant up from the ground).

I thought there might be something in GeneralUtilities or in some other developer packages…




Sorry, I’m lost with your botanical metaphor. Could you try to explain further?
– Dr. belisarius
Mar 29 at 22:05



Sorry it’s spring and I have plants on my mind… I’ll add a concrete example.
– M.R.
Mar 29 at 22:06



Essentially talking about a dependency tree for a piece of code
– M.R.
Mar 29 at 22:14



Have you tried DumpSave[“”] without supplying a second argument?
– barrycarter
Mar 30 at 2:09



I am dealing with the same issue, while using DumpSave. I did try DumpSave but it does not seem to accept a single argument, at least on MMA 10.2.
– Trad Dog
Mar 30 at 9:17


1 Answer


I think Save is the built-in function that come closest to what you are looking for.

a = 5; n = 1/2;
f[x_] := a + x^2

Save[“stdout”, f]



What it f relied on a function g which relied on a function h in package i?
– M.R.
Mar 30 at 0:43



You could try it and see what happens. You could reflect on the fact that definitions of Plus and Power don’t show up.
– m_goldberg
Mar 30 at 1:08