## Computer Science & Engineering 505 Assignment 1

Due: October 6, 1999

1. Algol-60 has been a major influence on programming language design. Describe two features of Algol-60 that have appeared in a subsequent language of your choice. How are the features similar in the two languages, and how have they changed?

2. Consider the following code fragment. integer sum, n; sum := 0; n := 0; for i := 1 step n+1 until 3 do begin sum := sum+i; n := n+1 end Consider a debate regarding the value of `sum` after the termination of the loop. A conservative Algol theologian would say "read section 4.6.4.2" (which defines the semantics of for loops). A liberal Algol theologian (say a Unitarian) might respond "if section 4.6.4.2 is to be taken literally, the loop variable `i` has a perfectly well defined value after the loop terminates. But if section 4.6.5 is also to be taken literally, then `i` must be undefined. So we can't take all parts of section 4.6 literally."

Under the conservative interpretation, what is the value of `sum` and `i` after the termination of the loop?

What is the value of `sum` and `i` after the termination of the loop under the liberal interpretation? (Since we're taking the liberal point of view here, you get to choose your own personal interpretation of the Report.)

What are the implications of both views for the implementation of for loops?

3. In Algol-60 arrays as well as simple variables can be own. Arrays can also be dynamic. Discuss feature interaction in dynamic own arrays.

4. Consider the following program in an Algol-like language. begin integer n; procedure p(j, k: integer); begin n := n+1; j := j+4; k := k+7; print(j,k,n); end procedure p; n := 0; p(n,n); print(n); end; What is the output when j and k are both:
1. passed by value?
2. passed by value result?
3. passed by reference?
If any variables are aliased in any of the cases, say so. Explain your reasoning in each case.

5. Consider the following program in an Algol-like language. begin integer n; procedure p(j, k: integer); begin n := n+1; print(j,k); end procedure p; n := 0; p(n,n+10); end; What is the output when j and k are both:
1. passed by value?
2. passed by name?
3. passed by reference?