Com Sci 221 — Programming Languages Assignment #1 — Winter 1994 Due Wednesday, 12 January

Write a procedure to reverse a list of arbitrarily many (within some reasonable limits which you may impose) single characters in each of the following languages: Pascal, C, ML, Scheme, and Prolog. In each case, choose an appropriate data structure to represent lists of single characters. 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.

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 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.

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.