AI-Portal Artificial Intelligence for Enthusiasts

Parameter evaluation in programming languages

How does parameter evaluation influences programming?

First of all how are possible evaluations?

Method 1: Evaluate each parameter at a time and then pass the result to the next level ( called function for example ). In this case parameters are send by value.

Method 2: Send the parameters as they are, and let the next level evaluate them, if necessary. In this case parameters are send by name.

At first glance, there is not an important difference, however, looking closer we may notice:

- Sending parameters by name implies a bigger stack because all calls need to store partial results and all unapplied parameters

- Sending parameters by name implies having evaluation at a later time, which in state-full programming languages/environments this may bring up some problems. On stateless situations evaluation time is non significant.

- Sending parameters by value may bring unnecessary computations because we may not need the evaluation of certain parameters.

Here is an example written in C programming language

int myFunc( int parameter)

{

return 0;

}

 

In this case the evaluation of parameter, in the case of the call myFunc( someOtherFunc(some params )), computing the parameter value is useless.

Lets say someOtherFunc does the following:

int someOtherFunc( some params )

{

while (1) ;

return 0;

}

In this case, evaluation by value will have a serious problem because program will never end.

However, evaluation by name will end in a normal fashion because there is no need to call someOtherFunc.

Stateless programming languages can fully take advantage of this lazy-evaluation, but on state-full situations, someOtherFunc may change environment so it''s evaluation can become mandatory.

The C programming language uses applicative evaluation, which is by value, while functional programming languages like Haskell use lazy-evaluation.

Get more Joomla!® Templates and Joomla!® Forms From Crosstec