Parameter Passing
Parameter passing is a type of technique used to transfer parameters from a function or procedure to another function or procedure. There are certain functions that can operate well without needing outside parameters. It is also possible to access global parameters from a subroutine, function or procedure. Although these designs are possible parameter passing is sometimes the best solution when the programmer wants the function to be independent from the calling function. If parameter passing is employed the code for a particular function can be used in other projects, debugging this code will be greatly simplified, therefore less time consuming, and any subsequent versions of the function will not affect the entire program. This is a very useful technique since many complex programs are written in special pieces or functions where each has a defined task. Parameter passing allows the values or entities represented as parameters to be transferred back and forth and utilized by these functions without having to redefine them within each piece. This saves programmers much time and effort. There are many types of parameter passing techniques with call-by-value, call-by-name, and call-by-need being three of the most widely utilized. The specific parameter passing technique employed in a situation where a parameter is declared as a variable affects whether the value of the parameter is computed by the caller or the called function and whether the called function can modify the value of the parameter as seen by the caller.
Call-by-value is a parameter passing technique that utilizes parameters that are evaluated or defined before the called function is entered. Only the value of the parameter is transferred to the called function and so the caller function does not see the value of the parameter being affected by the called function. This parameter passing method is efficient but less likely to terminate when dealing with infinite data structures and recursive functions.
Call-by-name is the opposite of call-by-value in that it is a parameter passing technique that does not pre-evaluate the parameter before passing it. This parameter passing technique was first established by Algorithmic Language 1960 (Algol 60), a portable language for scientific computations. Usually when dealing with macros a parameter is passed using call-by-name. Instead of passing the evaluated parameter a pointer to some code that will return the value of the parameter and an environment giving the values of its free variables are passed. Using this technique a normal form, the state of a term that contains no reducible expressions, is guaranteed to be achieved if one exists. In order to avoid repeated evaluation of the same expression over and over when implementing functional programming languages the call-by-name parameter passing is often combined with graph reduction. Graph reduction is a technique that represents and expression as a directed graph. The combination of graph reduction and call-by-name is called call-by-need parameter passing.
Call-by-need parameter passing is a technique that delays evaluation of a function parameter until it is needed by that function. This is done because the parameter is part of a conditional or primitive function. This term first appeared in 1971 in a thesis written by Chris Wadsworth, a student from Oxford.
This is the complete article, containing 523 words
(approx. 2 pages at 300 words per page).