Com Sci 221 --- Programming Languages
Assignment #1 --- Autumn 2000
Due Monday, 2 October

This assignment is intended to make you run a trivial program in several different programming languages, so you don't struggle with silly logistical surprises on later and more interesting assignments. It also touches structural concepts in a superficial way.

Make sure to follow the general instructions for performing and submitting homework.

Write a recursive or iterative procedure to reverse a list of arbitrarily many single characters in each of the following languages: C (or C++), ML, Scheme, and Prolog. Some of these languages have a reverse function built in---for exercise please write your own recursion or iteration. Reverse is given as an example in the manuals for some of these languages. It's OK to find the program in the manual. In each case, choose an appropriate data structure to represent lists of single characters. Your procedure and data structure may impose a limit on the length of the list, as long as that limit is trivial to change without affecting the structure of the procedure.

Demonstrate your procedures on an interesting set of inputs. In this, and all subsequent programming problems, part of the assignment is to figure out a set of test cases that really illuminates the behavior of your code. A small handful of cases (perhaps 3 or 5) should be sufficient. Strive for clarity rather than for volume or cuteness.

Notice that I asked you to write ``procedures,'' rather than ``programs.'' In most programming assignments, I am interested in the transformation of a data structure representing a list into another data structure, not in the input and output of text representing that data structure. Of course, in some of the programming languages you will need to embed your procedure in a program containing input and output commands in order to demonstrate its behavior. In that case, make sure that it is easy for a reader to separate the required procedure from the program that contains it. In some of the programming languages you may be able to use interactive interpreters to avoid describing input and output procedures.

In this assignment, I am only interested in the data structure for list. I chose single characters as elements of lists because that allows you to test things very simply in all of the programming languages involved. I am not interested in fine points regarding the representation of characters. If it's convenient to represent a single character by a string of length 1, that's fine. I'm also not interested in fine points of the output format. The output should be highly readable, so that I can see very easily that a given input, processed by your procedure, leads to a given output (so, e.g., do not collect all outputs together, group them with their inputs and some clear indication of the running of the procedures). But it doesn't matter precisely how characters are presented in the output (e.g., with or without quotes).

Explain very briefly the important and fundamental structural reasons why the following Pascal program does not satisfy the requirements of the assignment. Do not waste time describing fine points of Pascal.

      program reverse(input, output);

      var
              length: 0..10;
              list: array[1..10] of char;

      begin

              length := 0;

              while not eoln do begin
                     length := length + 1;
                     read(list[length]);
              end;

              writeln('Here is the reversed list:');

              for i := length downto 1 do begin
                     write(list[i])
              end;

              writeln

      end.

Last modified: Mon Sep 25 14:42:56 CDT 2000