Assignment 11, due Apr 19

Part of the homework for CS:2820, Spring 2019
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Assignments are to be turned in on paper. On every assignment, write your name, course and section number at the top of each page. Write your name as it appears in your university records! Use the section number for which you are registered! We will not do detective work to figure out who did what. Work must be legible.

Homework is due on paper in discussion section, usually at the start except when the assignment indicates that time to work on the assignment will be provided in class. Exceptions will be made only by advance arrangement with your TA (excepting "acts of God" outside your control). Never push homework under someone's door!

  1. Background: Enough people had difficult on the exam that it's worth going back and working on some λ-expressions. Here's a familiar looking Java main program:
    public static void main( String[] args ) {
        X      p = (String s) -> "p( " + s + " )";
        Y      q = (X j) -> ( (String s) -> j.x( j.x( s ) ) );
        X      r = q.y( p );
        System.out.println( "Value is: " + r.x( "one" ) );
    }
    

    You saw this in Homework 10, and you are welcome to use the code from the posted solution to homework 10 to test your solution to this probmem.

    A problem: Rewrite the line that defines and initializes q so that it uses explicitly declared and named inner classes and no λ-expressions.

    Suggestion: Eliminate the outer λ-expression first, test your result, and then work on eliminating the inner one. (1.0 points)

  2. Background: Consider the following code from class wire in the posted solution to MP4 (it is unchanged in MP5):
    /** tell the wire that its input has changed
     *  @param now the time at which the change occurs
     *  @param value the new value of that input
     */
    public void inputChange( float now, int value ) {
        Simulation.schedule(
            now + delay, (float t) -> this.outputChange( t, value )
        );
    }
    
    private void outputChange( float now, int value ) {
        final int comp = 1 - value; // logical complement of the value
        System.out.println( "time "+ now +" "+ comp +"->"+ value +" "+ this );
        destination.inputChange( now, value );
    }
    

    A problem: Rewrite this to work in the new framework distributed on April 15. Suggestion: You can entirely eliminate the outputChange method. Warning: Beware of problems with this. (1.0 points)

  3. Background: The previous problem suggested eliminating Wire.outputChange. Now, consider the Gate.outputChange method.

    a) How many places in the code of MP4 (the answer is the same for MP5) is this called or scheduled from? (0.5 points)

    b) What consequence does this have with regard to eliminating Gate.outputChange. Specifically, would you recommend eliminating it? Why or why not? (0.5 points)