WOLFRAM LANGUAGE TUTORIAL

Documentation Constructs

When you write programs in the Wolfram Language, there are various ways to document your code. As always, by far the best thing is to write clear code, and to name the objects you define as explicitly as possible.

Sometimes, however, you may want to add some "commentary text" to your code, to make it easier to understand. You can add such text at any point in your code simply by enclosing it in matching and . Notice that in the Wolfram Language, "comments" enclosed in and can be nested in any way.

You can use comments anywhere in the Wolfram Language code you write.
In[1]:=
Click for copyable input
Out[1]=
(*text*)a comment that can be inserted anywhere in Wolfram Language code

Comments in the Wolfram Language.

There is a convention in the Wolfram Language that all functions intended for later use should be given a definite "usage message", which documents their basic usage. This message is defined as the value of f::usage, and is retrieved when you type ?f.

f::usage="text"define the usage message for a function
?fget information about a function
??fget more information about a function

Usage messages for functions.

Here is the definition of a function .
In[2]:=
Click for copyable input
Here is a "usage message" for .
In[3]:=
Click for copyable input
Out[3]=
This gives the usage message for .
gives all the information the Wolfram Language has about , including the actual definition.

When you define a function f, you can usually display its value using ?f. However, if you give a usage message for f, then ?f just gives the usage message. Only when you type ??f do you get all the details about f, including its actual definition.

If you ask for information using about just one function, the Wolfram Language will print out the complete usage messages for the function. If you ask for information on several functions at the same time, however, the Wolfram Language will give the name of each function, if possible with a link to its usage information.

This gives all the symbols in the Wolfram Language that start with "Plot".

If you use the Wolfram Language with a textbased interface, then messages and comments are the primary mechanisms for documenting your definitions. However, if you use the Wolfram Language with a notebook interface, then you will be able to give much more extensive documentation in text cells in the notebook.