I often post code for functions on Stack-Exchange, and then later find that they are unexecutable - that people can't use them because I mistakenly omitted some private functions or values that are needed. This function calls that function and that function calls another funciton in a package that I didn't mention, and so forth....

This happens frequently enough that I find myself needing a tool that can effectively pull the function up by its roots, returning just what is needed (certain functions, various symbols, referenced files, parts of packages, etc...) to run the function in an example and nothing more.

I imagine that this would be very useful for visualizing the inner workings of functions in general as well!

  • $\begingroup$ Maybe FullDefinition does what you want, assuming you capture its printed output and then export it appropriately — e.g. for a symbol f and its dependencies use FullDefinition[f] // ExportString[#,"Text"]&. $\endgroup$ – Stephen Luttrell Dec 4 '14 at 18:19
  • $\begingroup$ FullDefinition would certainly be helpful but omits too much, such as values that are not computed with DelayedSet $\endgroup$ – user5601 Dec 4 '14 at 20:32

This isn't a problem you should try to solve automatically. Use good code hygiene and make sure you don't call private functions. You should (aim to) understand your code well enough that you don't get surprises like this --- you wrote it, and you know it better than anyone else. If there are surprises even to you, how will anyone else understand it?!

Whenever I think I've got a complete snippet of code, I quit the kernel and check it. It can be a little irritating but that's by far the best time to catch problems.

  • 2
    $\begingroup$ +1 for "quit the kernel and check it". Anyone looking to post a question should do this before posting. It's part of the process of creating a minimal example. $\endgroup$ – Szabolcs Mar 29 '15 at 2:07

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.