Computer Science & Engineering 505
Concepts of Programming Languages
Assignment 3

Oct 14, 1994
Due: October 21, 1994


  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 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.

  3. 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?
    Explain your reasoning.

  4. Can aliasing arise in a functional language? If so, what is its effect?

  5. What is the output from the following Algol-like program? begin procedure whale (n: integer, p: procedure); begin procedure squid; begin print("in procedure squid -- n="); print(n); end procedure squid; print("in procedure whale -- n="); print(n); squid; p; if n<5 then whale (n+1,squid); end procedure whale; procedure octopus; begin print("in procedure octopus"); end procedure octopus; whale(1,octopus); end;

  6. Issues of lexical scoping and functions or procedures as parameters are not unique to Algol-style languages. Consider the following Miranda program: double x = x*2 whale n func = whale (n+1) func, n<4 = whale (n+1) squid, n=4 = whale (n+1) func, n<10 = func n, n=10 where squid k = n+k What is the result of evaluating whale 0 double Explain. (You can run the program if you want to check your work -- it is on lynx on ~borning/miranda/whale.m if you want to avoid typing it in.)

  7. Unlike Algol, in Miranda functions can be values returned by other functions. Lexical scoping rules must still be obeyed. Here is a variation on the above program: double x = x*2 dolphin n func = dolphin (n+1) func, n<4 = dolphin (n+1) squid, n=4 = dolphin (n+1) func, n<10 = func, n=10 where squid k = n+k What function is returned by evaluating: dolphin 0 double What is the result of evaluating: dolphin 0 double 100 Explain.