I have defined a bunch of functions over several different files, and I would like a list of prototypes of all the functions I have defined in my current session (I want the mathematica equivalent of the .h file for my .c file).

For example, if I defined two functions,

f[arg1_, arg2_]:= Module[...];
g[t_]:= Module[...];

Then I would want the following list (alphabetized, of course):

f[arg1_, arg2_]

It would be nice if the list could be exported to a notebook or pdf for quick viewing. How can I accomplish this task?

  • $\begingroup$ You are aware that referring to this as "the mathematica equivalent of the .h file for my .c file" is actually a misnomer? Mathematica doesn't need header files. $\endgroup$ Commented Nov 19, 2013 at 16:04
  • $\begingroup$ @SjoerdC.deVries C does't need header files either... I could just put prototypes at the top of the .c file. I write header files to give me a clean organized list of all the things that are going to appear in the .c file. It is a coded form of documentation. $\endgroup$
    – nullUser
    Commented Nov 19, 2013 at 19:31
  • $\begingroup$ There are conditions where those headers are needed, for instance in functions that mutually reference each other. Not so in Mathematica. $\endgroup$ Commented Nov 19, 2013 at 21:47
  • $\begingroup$ @SjoerdC.deVries Prototypes are needed for mutually referencing functions. A separate header file is not. $\endgroup$
    – nullUser
    Commented Nov 20, 2013 at 5:10

3 Answers 3


Here's one solution (that needs a bit of improvement to make it useful):

functionList[context_String] := 
   HoldForm @@@ Flatten[
      (ToExpression[#, InputForm, DownValues] & /@ Names[context <> "*"])[[All, All, 1]]]]

Now just do functionList["Global`"].

It does not handle UpValues, SubValues, OwnValues, but most of your functions are likely to use DownValues.

Considering your use case, take a look here too:

Writing usage messages is going to be a much better solution. Simply taking the pattern you used in the function definition (as I did above) might sound like a good idea at first, but it conflicts with some common Mathematica patterns such as memoization.

  • $\begingroup$ This is perfect for my needs! $\endgroup$
    – nullUser
    Commented Nov 19, 2013 at 20:31
  • $\begingroup$ Hi, Szabolcs. Thank you for your solution. I would like to know further how to list function within current notebook? $\endgroup$
    – matheorem
    Commented Sep 9, 2017 at 6:50

There is something close to what you ask for built into Mathematica. It is the function called Information. In the form you would use to get what you asked about, there is a keyboard shortcut, the question-mark character.

a = 42;
f[arg1_, arg2_] := Module[{}, {arg1, arg2}]
g[t_] := t^2


Each of the symbols shown above is actually a button and gives further information about the definition of the symbol when clicked on. For example, were I to click on f, I'd get

f[arg1_, arg2_] := Module[{}, {arg1, arg2}]

The string "Global`*" is interpreted by Information as meaning "show me all the symbols defined in the Global context". A context is a Mathematica namespace and Global is the namespace where user defined symbols go unless you do something special to prevent it.

Note that this works only for symbols that have been evaluated

  • $\begingroup$ This is a cool thing to know, but it doesn't really solve my problem. I really want the arguments included. The reason I'm doing this is so I can remember what arguments all my functions take. $\endgroup$
    – nullUser
    Commented Nov 19, 2013 at 19:28
  • 1
    $\begingroup$ @nullUser You probably might be interested in defining templates for your functions: Multiple templates for a single user-defined function $\endgroup$
    – rm -rf
    Commented Nov 19, 2013 at 20:05
  • $\begingroup$ But as I said in my answer, if you click on the function name you will see all the definitions you have made including all the argument patterns it accepts. $\endgroup$
    – m_goldberg
    Commented Nov 19, 2013 at 21:09

How's your pattern matching? Mine's not at all good (yet), but you might be able to rustle up some kind of solution using this as a starting point:

functionScan[p_] := 
  result : ( 
     WordCharacter .. ~~ "[" ~~  Except[ "]", _] .. ~~ "]" ~~  _ ~~  
      ":=" ) :> result]

files = FileNames["GraphicalLSystems*.nb"];
result = functionScan[Import[#, "Plaintext"]] &  /@ files

with the result:

{{"LSystem[0,  axiom_,  _] :=", 
  "LSystem[iterations_,  axiom_,  rule_] :=", 
  "LOGO[commands_,  {startx_,  starty_,  starta_}] :=", 
  "geometry[system_,  iterations_] :=", "thumbnail[system_] :=", 
  "Module[{gosper,  abs,  arg}, gosper[abs_,  arg_,  baseAngle_] :="}, 

Formatting the results should be easier!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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