# How to package a function for export?

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!

• 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"]&. – Stephen Luttrell Dec 4 '14 at 18:19
• FullDefinition would certainly be helpful but omits too much, such as values that are not computed with DelayedSet – user5601 Dec 4 '14 at 20:32