CS 4536 Homework 4: Mutation and Parameter Mechanisms

Due: Thursday Feb 7, 11:59pm via turnin (assignment name hwk4)
Collaboration Policy: Pairs Permitted (except for optional makeup work in question 3)


Neither interpreters nor Scheme code are required in this assignment. Question 3 has an optional interpreter component for those of you looking to make up for points lost on the first two assignments.

  1. Java Parameter Mechanisms
    1. People often summarize the difference between call-by-value and call-by-reference as "if a function F is call-by-value, mutations to parameters within F aren't visible outside of F". Write two short Java programs, one whose result indicates whether Java uses call-by-value or call-by-reference for flat values (such as ints) and one that makes the same assessment for objects (similar in spirit to the boxes we used in our interpreter). For each program, include a comment stating your answer (by-value or by-reference) and explaining how your program goes about the check. Good solutions will support your answer and refute the other: for example, if you determine that Java uses call-by-reference for flat values, your program should illustrate (a) that it behaves like call-by-reference and (b) does not behave like call-by-value. (Note: printfs can be helpful in illustrating these differences.)

      If your Java skills are rusty, you may prefer to do this assignment first in Scheme (using boxes in place of objects) and then map your Scheme program over to Java.

    2. Given your results, do you agree or disagree with the summary statement? Why?

  2. ML Parameter Mechanisms

    ML (another functional language) forces programmers to annotate all mutable data structures using references (ML's counterpart to boxes). Any data structure that isn't annotated is considered immutable. What trade-offs does this design introduce with respect to each of performance (time and/or space) and modularity? You may discuss other trade-offs if you wish.

  3. Textbook problem 14.3.2 (page 139), subpart 3 (not parts 1 and 2)

    Subpart 1 asks you to modify the interpreter. You may find that useful in working on this problem, but you do not need to submit your interpreter as part of your solution. If you do write this interpreter, you may turn it in as part of "make-up" work towards points lost on the first two assignments, but this is not required. Your interpreter would have to support the new ref construct to warrant make-up points. It would not need to support refprocs. Include test cases in your interpreter file. The interpreter portion must be your own work, rather than work done with a partner.

What to Turn In

Turn in a file containing your Java program for question 1 and a text file containing your answers to problems 2 and 3. As with homework 3, please submit a text file, rather than Word or something else that we need an application to open (we want to be able to spool your file directly to the printer). If you are submitting an interpreter, simply upload that as a separate file.


FAQ

Nothing yet ...