CS 3304 Homework #7

Date Assigned: October 29, 2003
Date Due: November 5, 2003, in class, before class starts
  1. (5 points) Read Section 8.3.4 of your textbook and give the name of a ML higher-order function that performs such an "iteration based on data structures."

  2. (10 points) Using the non-deterministic guarded-if and guarded-do constructs, write the following imperative programming commands (with their obvious meanings):

    • if b then statement1 else statement2
    • if b then statement
    • while b do statement
    • repeat statement until b
    • for i:=1 to 100 do statement

    Read Section 8.5 of your textbook for further details.

  3. (5 points) Which parameter passing mechanism does SML use? Explain with reasons and defend your answer with code. Story-writing will fetch you zero points.

  4. (5 points) Problem 5 of Chapter 9 Problem Set from your textbook (page 395).

  5. (25 points) Given the code fragment and output below, which of the five parameter passing mechanisms will produce the output? (there may be more than one). Defend your answer. The code fragment is assumed to be in a block-structured language with static scoping, like Pascal (but not Pascal).
    
    program quiz;
    
    var     i : integer;
    	A : array [1..200] of integer;
    
    	procedure foo(x,y);
    	begin
    		i := x+y;
    	end;	
    
    begin (* of main program *)
       i := 2;
       A[i] := 99;
       foo(i, A[i]);
       print (i);
       print (A[i]);
    end.
    
    The output:
    
    2
    99
    

Return Home