# CS334: HW 7

## Instructions

This homework has three types of problems:

• Self Check: You are strongly encouraged to think about and work through these questions, but you will not submit answers to them.

• Problems: You will turn in answers to these questions.

• Programming: We’ll do this in the conferences this week. More details then.

## Reading

1. (Required) Mitchell, Chapters 10–11

2. (Required) The Scala Tutorial

## Self Check

### 1. Smalltalk Run-time Structures

Mitchell, Problem 11.4

The given conversions between Cartesian and polar coordinates work for any point $$(x,y)$$, where $$x \geq 0$$ and $$y > 0$$. Do not worry about points where $$x < 0$$ or $$y \leq 0$$. The figure P.11.4.1 appears on page 332.

You should try to write reasonably accurate Smalltalk code for part (b), but you do not need to use Squeak.

## Problems

### 1. Removing a Method (10 points)

Mitchell, Problem 11.7

### 2. Protocol Conformance (15 points)

*Mitchell, Problem 11.6**

(You will find it useful to answer Problem 11.7 first before working on this one.)

### 3. Subtyping and Binary Methods (10 points)

Mitchell, Problem 11.8

### 4. Delegation-Based OO Languages (15 poitns)

Mitchell, Problem 11.9

## Programming

We’ll work on Scala code for the homework in Conferences next week. Before your conference, set up your Scala environment, either on your own computer or on the lab computers so that you are ready to start writing some code at the start of the conferences.

You might also want to go back to your notes from Thursday’s lecture and try out some of the examples I went through to better understand Scala’s syntax and features.

See instructions here for setting up Scala.

The scala command will give you a “read-eval-print” loop, as in Lisp and ML.

You can also compile and run a whole file as follows. Suppose file A.scala contains:

object A {
def main(args : Array[String]) : Unit = {
println(args(0));
}
}

You then compile the program with scalac A.scala, and run it (and provide command-line arguments) with “scala A moo cow”.

#### Resources

There is plenty of very detailed information about Scala available online (e.g., http://www.scala-lang.org — just web search for “Scala Language”). I suggest that you look at tutorial-style descriptions of the features of interest as well as the Scala Language Specification for some of the specifics.

There is also extensive online documentation for the Scala libraries at http://www.scala-lang.org/api/.

## What To Turn In

#### Problems

Your submitted homework should:

• be clearly written or typed,
• include your name and HW number at the top,
• list any students with whom you discussed the problems,
• be a single PDF file, with one problem per page, and
• be submitted to Gradescope by the due date.

#### Programming

Your submitted programs should:

• be readonably documented and tested,
• list any students with whom you discussed the programming,
• be committed and pushed to your GitLab repository by the due date, and
• be submitted to Gradescope by the due date.

To submit your code in Gradescope, navigate to the submission page for this assignment’s programming component, and select the option to submit files. Then select and upload your source files. If you worked with a partner, only one of you should submit your code, and please indicate who your partner is when you upload your files.

Note: The shared repository you are using is either your own or your partners. The other one will be unused. There is no need to do anything to that repository. Our submission scripts will ignore unused repositories and look only at the onces with completed solutions.