From: Eric S. Raymond Date: Tue, 2 Mar 2004 05:22:34 +0000 (+0000) Subject: Add two pages. X-Git-Tag: 1.0~47 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=0c6744caa624d4cf5f36cecc492a8f935d069e8a;p=mad.git Add two pages. --- diff --git a/doc/mad-manual.xml b/doc/mad-manual.xml index cd166e2..6994edb 100644 --- a/doc/mad-manual.xml +++ b/doc/mad-manual.xml @@ -1998,7 +1998,8 @@ statement is simply: ERROR RETURN -(An example of its use is shown near the end of subsection 3.8.3). +(An example of its use is shown near the end of ). In order to use it in a function evaluation, the last (right-most) argument of the function must be the label of a statement @@ -3179,20 +3180,19 @@ program. There are two main types of functions: The internal function and the external function. Since these are quite similar in many ways, that part of the -description which is specific to external functions - +description which is specific to external functions will be given in , that which is specific to internal functions in , and that which is common to both types -will follow in subsection 3.8.3. Throughout this section a -single-valued function will be called a "function", and a function -with multiple outputs and/or multiple exits will be called a -"procedure". For the purposes of this manual a recursive function is -one whose definition contains calls for the function being defined -- -or calls for functions which ultimately call the one being defined. -Recursive functions have the same structure as other functions -although, in general, they will include statements of the type -described in , and certain +will follow in subsection . +Throughout this section a single-valued function will be called a +"function", and a function with multiple outputs and/or multiple exits +will be called a "procedure". For the purposes of this manual a +recursive function is one whose definition contains calls for the +function being defined -- or calls for functions which ultimately call +the one being defined. Recursive functions have the same structure as +other functions although, in general, they will include statements of +the type described in , and certain considerations should be borne in mind when constructing such functions. These considerations arise from the fact that names , instead of values, are used as function arguments. @@ -3247,11 +3247,117 @@ INTERNAL FUNCTION SUMSQ.(X,Y,Z) = X * X + Y + Z * Z - T * T As indicated above, X, Y, and Z, as they occur here, are dummy -variables, and (X, Y, Z) is the dummy variable list. +variables, and (X, Y, Z) is the dummy variable list. The current value +of T, however, will be obtained and used each time the value of the +function is needed. An example of theuse of the function so defined +would be: + + +A = 1.-SUMSQ. (U, V + 3, W) .P..5 + + +Only nonsubscripted names of variables (either individual or array) or +names of functions (without arguments) may appear in the dummy +variable list. For this type of function definition no END OF +FUNCTION statement is required. In the user of the function is an +expression, the arguments may be any expressions that agree in mode +with the corresponding argument in the declaration. + +In the example: + + +INTERNAL FUNCTION POLY. (N, X, FN.) = FN. (J*X).P.N - X/XBAR + + +which might be used in the statement + + +BETA ZQ = POLY.(M + 1, Y, SIN.) + POLY.(M -1, Z, COS.) + + +it is understood that if N is in the integer mode, then so are Y and +Z. Both M and N would have had to be declarted to be in the integer +mode, of course. Similarly, the values of SIN. and COS. must be the +same mode as the values of FN. Moreover in the use of functions this +mode correspondence cannot be checked by the translator. + +The function POLY. has as one of its arguments the name of a function. +In the statement BETA the function used in the first term to the right +of the "=" sign is SIN. and in the second term COS.. Hence statement +BETA is then equivalent to: + + +ZQ = SIN.(J * Y).P.(M + 1) - Y/XBAR + COS.(J*Z).P.(M-1)-Z/XBAR. + + +Internal and External Functions + +Each function definition (except single statement definitions +described in ) may define any +number of functions and/or any number of procedures. Within one +function definition all functions and procedurews defined must use +exactly the same set of arguments. In other words, the functions +CPADD.(X,Y,A,B)and CPMPY.(X,Y,A,B) may be defined, if desired, by one +definition, but the functions SIN.(X) and ARCTAN.(X.Y) would require +separate definitions. + +Similarly, the procedures RXSUB. and ADAMS. could be defined by the +same definition if they have the same outputs, say Z and W, and the +same input parameters, say X, Y, T, and N. However, if they did not +have exactly the same outputs and the same inputs, they would require +separate declarations. + +In the use of a function (i.e., the + call for it) the arguments may be constants, +variables, or expressions. However, if one of the arguments appears +to the left of an "=" sign in a substitution statement in the defining +program it is not meaningful to use a constant or an expression for +that argument in the call. As mentioned earlier, the arguments in the +call for a function cannot be checked for correspondence in mode and +number to arguments in the definition. + +The general form of all function definition programs is as +follows: + + +INTERNAL FUNCTION (X) +ENTRY TO COS. +... +... +... +ENTRY TO SIN. +... +... +... +FUNCTION RETURN ALPHA + J - 3 +ENTRY TO TAN. +... +... +... +FUNCTION RETURN BETA/K5 - 4 * D +END OF FUNCTION + + +The first statement (INTERNAL FUNCTION (X)) is a function +declaration (i.e., declares that the following +statements define a function). If this is defining an external +function, the declaration would be EXTERNAL FUNCTION (X). Following +the words INTERNAL (or EXTERNAL) FUNCTION is the dummy variable list +((X) in this example). The END OF FUNCTION declaration is the last +statement in the function definition program. (In an external + +function definition this is also the last statement in the program.) +An entry must provided for each function being defined, but several +functions may share any number of FUNCTION RETURN statements. An +entry statement merely marks a point of entry, and does not effect the +sequence of computation in any way. The expression after the word +"RETURN" indicates that on this return the value of the function is to +be the value of that expression. + @@ -3535,7 +3641,7 @@ READ READ FORMAT INPUTS,A,B,N,R -Program:It is assumed here that f +Program: It is assumed here that f (referred to as F. in the program) will be defined as an internal function.)