# Hiding body of a module or function in mathematica

Is it possible to hide the body of a module or function in MMA?

For example I would like to turn this:

myModule[]:=[{},

Body of module

]


to:

myModule[]:=[{},...]


where .... is the uncollapsed part of the module.

If this is not possible, is it possible to write all the module definition in .m file and then import those module and function definitions into MMA notebook?

Yes it is possible, but in an indirect way. Here is one method:

(I have to use screen shots to explain). Here is an example of myModule whose body prints a message to the screen, but the body is hidden

This is done by making the implementation foo in this case, be in a separate cell, then utilizing cell->cell properties feature to close the cell from view so it becomes hidden. The following two steps needs to be done:

The important point, is to have the implementation in a different cell to be able to close it. You can't close part of a cell. On a cell on its own. This can be easily extended for modules that take arguments as well.

Update:

To answer the comment on how to call own function in .m file from notebook. Please see these complete answers: How do I save a variable or function definition to a file? and How can I save and recall my own function?

The short answer, is that you can just do <<myfile.m to load your .m file. Once loaded, then the definition is there in memory and you can then call functions defined in the .m file. The functions in the .m do not show up in the notebook, but they are loaded in memory. You can see them only when you do ? on them or type the .m file.

• Could you please add to your answer how I can implement the module in a .m file or whatever format MMA uses and then call them from notebook? – MOON Nov 5 '14 at 12:56
• @yashar added note to answer your comment on .m file usage. – Nasser Nov 5 '14 at 13:04