Simula - Sample Code - Call By Name

Call By Name

Simula supports call by name so the Jensen's Device can easily be implemented. However, the default transmission mode for simple parameter is call by value, contrary to ALGOL which used call by name. The source code for the Jensen's Device must therefore specify call by name for the parameters when compiled by a Simula compiler.

Another much simpler example is the summation function which can be implemented as follows:

Real Procedure Sigma (k, m, n, u); Name k, u; Integer k, m, n; Real u; Begin Real s; k:= m; While k <= n Do Begin s:= s + u; k:= k + 1; End; Sigma:= s; End;

The above code uses call by name for the controlling variable (k) and the expression (u). This allows the controlling variable to be used in the expression.

Note that the Simula standard allows for certain restrictions on the controlling variable in a for loop. The above code therefore uses a while loop for maximum portability.

The following:

can then be implemented as follows:

Z:= Sigma (i, 1, 100, 1 / (i + a) ** 2);

Read more about this topic:  Simula, Sample Code

Famous quotes containing the word call:

    ... the most extreme conditions require the most extreme response, and for some individuals, the call to that response is vitality itself.... The integrity and self-esteem gained from winning the battle against extremity are the richest treasures in my life.
    Diana Nyad (b. 1949)