CSE 341 - Spring 2002 - Assignment 6 - Smalltalk Part 2

Due May 20, at the beginning of class, submitted as described below for each problem. The purpose of this assignment is to have you compare Smalltalk and Java style iteration, and to investigate the 'block' construct in Smalltalk.

  1. For this problem, you will write three new classes, so to make filing out easier, create a new class category 341-assignment6 and define your classes in this category. Define a linked list class in this category. (There is already a built-in class LinkedList with slightly different behavior, so name yours MyLinkedList.) MyLinkedList should have the methods specified below. (The main focus of this problem is iterators, so you are not required to implement other methods that you would expect in a list interface, like accessing an item by index.) You will also need an auxiliary MyNode class to instantiate for each linked list node.

    The do: method supports Smalltalk-style iteration. In standard Smalltalk style, this would be all you would need. However, for the purposes of this assignment, also define the iterator method as described above, which should return a list iterator object to support Java-style iteration. The iterator should be an instance of a class ListIterator, and should include next and hasNext methods (just as with the Java Iterator interface). You do not need to deal with the case of a list that is modified while there is an iterator active on it.

    For computer submission of your code, select the class category 341-assignment6 in a browser, and then pick 'fileOut' from the right-button menu. Then for the paper version, pick 'printOut'. (The 'printOut' option creates an HTML file which has nicer formatting. Unfortunately it isn't set up to file in correctly, however.)

    Testing. Test your linked list by making an instance of it, and demonstrating it in operation, using both the Smalltalk and Java style iteration, as well as the other methods specified above. For Java style iteration, demonstrate that you can have two iterators at the same time, functioning independently.

    You may want to initially run these tests in a workspace, but before submitting your homework, put the test cases and a copy of the transcript and other results in a file. To create this file for the electronic submission for your answer to this question, select the "open..." menu item, then "file list", then "add new file" in the upper-right-hand pane of the file list. This file will be used just like a workspace, except that you can save the contents. This testing output file should be submitted both via computer and on paper.

  2. Smalltalk blocks are a powerful construct. As discussed in class, a block holds some code that can then be evaluated repeatedly. Also, if a block references any non-local variables, it captures the non-local variables from the environment it was created in, and the block retains them even if the surrounding environment is no longer accessible otherwise.