C:/Musimathics_local/Musimat/MusimatTutorial/B0120.cpp

Go to the documentation of this file.
00001 #include "MusimatTutorial.h"
00002 MusimatTutorialSection(B0120) {
00003 Print("*** B.1.20 Invoking Functions ***");
00004 /*****************************************************************************
00005 
00006 B.1.20 Invoking Functions
00007 
00008 We had two situations where the function euclid() was followed by a list of arguments, once 
00009 where it was defined, and another where it was invoked. The arguments associated with the def-
00010 inition of euclid() are called its formal arguments. They are Integer m and Integer n. 
00011 The values associated with its invocation (integers 91 and 416) are called its actual arguments. 
00012 A function will have only one set of formal arguments that appear where the function is defined. 
00013 It will have as many sets of actual arguments as there are invocations of the function in a program.
00014 
00015 When a function is invoked, three things happen:
00016 
00017 1. The values of the actual arguments are copied to the corresponding formal arguments.
00018 
00019 If an actual argument is a constant, its value is simply copied to the corresponding formal argu-
00020 ment. Example: Print(3) copies 3 to the formal argument for Print().
00021 
00022 If an actual argument is a variable, its value is copied to the corresponding formal argument. Exam-
00023 ple: Integer a = 3; Print(a) copies the value of a (which is 3) to the formal argument for 
00024 Print().
00025 
00026 If an actual argument is another function, that function is evaluated first, and its return value 
00027 replaces the function. Example: For the statement Print(euclid(91, 416)), first 
00028 euclid(91, 416) is evaluated, and the result (which is 13) is substituted in its place. So the 
00029 statement becomes Print(13). Finally, the 13 is copied to the corresponding formal argument 
00030 of the Print() function.
00031 
00032 2. The body of the function is executed using the values copied to the formal arguments in the 
00033 first step.
00034 
00035 3. The return value of the function is substituted for the function call in the enclosing program. 
00036 
00037 *****************************************************************************/
00038 }}
00039 
00041 /* $Revision: 1.4 $ $Date: 2006/09/12 17:37:59 $ $Author: dgl $ $Name:  $ $Id: _b0120_8cpp-source.html,v 1.4 2006/09/12 17:37:59 dgl Exp $ */
00042 // The Musimat Tutorial © 2006 Gareth Loy
00043 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00044 // and published exclusively by The MIT Press.
00045 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00046 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00047 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00048 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00049 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00050 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00051 // The Musimat website:                 http://www.musimat.com/
00052 // This program is released under the terms of the GNU General Public License
00053 // available here:                      http://www.gnu.org/licenses/gpl.txt
00054 

Generated on Tue Sep 12 10:14:24 2006 for Musimat Tutorial by  doxygen 1.4.7