"logo.gif"  
Main
Read Online
Download PDF
Additional resources
Revision history
Known typos/bugs
Report a bug
License terms
About the author
"node48_1.gif" "node48_2.gif" "node48_3.gif"

4.8 Larger functions, local variables and the code modularization

In the majority of real situations, the code for a typical function is longer than one or two lines (in other words, not every problem can be solved by one - liners). Also, it is often convenient to introduce intermediate variables, both to avoid redundant computations and to improve the code readability.  Such variables one has to localize, in order to avoid name conflicts with the global variables already defined in the system, and in general not to "pollute" the global name space. On the scale of a single function or program,  there are 3 constructs in Mathematica which provide this functionality: Module, Block and With. These constructs are explained in detail in Mathematica  Book and Mathematica  Help, so I will say just a few words about them here. On the larger scale, this is supported through the system of packages - we will consider them in part II.

"node48_4.gif"
"node48_5.gif"
"node48_6.gif"
"node48_7.gif" "node48_8.gif" "node48_9.gif"

Created by Wolfram Mathematica 6.0  (05 February 2009) Valid XHTML 1.1!