Assignment 4
CS471 Programming Languages I
Fall 1996
Assignment: Functional languages
This assignment examines the abilities of ML to process lists and to handle functions as first-class values. Also to generate graphics as a Postscript program.
The Task
Take the definition of the "little quilt" on page 370 of Sethi, and augment it to output a Postscript program that draws any quilt.
You can use the function show on pages 376-378 as a model, and write any auxiliary functions you think are necessary.
Standard ML
We have the standard ML system of New Jersey (SML-NJ) available in our UNIX environment. You must have /usr/unsupported/bin in your path to use it. To start ML, type
%sml
The interpreter prompt is
-
Any ML expression typed in, and terminated with a semicolon will be evaluated and the value typed back, with a type inferred. See chapters 8 and 9 for examples.
To end a session, type ctrl-D at the prompt.
Files containing ML code may be loaded with:
- use "filename";
Any errors will be reported, and the file can be edited and re-used.
Output
You can use standard output in two ways:
- print "abcd";
or
- output(std_out, "abcd");
will both print the string on the screen.
Output to a file can be achieved with:
- val out = open_out("filename"); - output(out, "abcd"); ... - close_out(out);
These commands will put the string "abcd" in the file called filename, in the current directory.
Postscript
A Postscript file must start with the line
%!Postscript
and to print anything, it must have
showpage
at the end. Send the file to a laser printer with
%lpr -Pprinter filename.ps
where printer is the name of one of the laser printers in the CS domain, and filename.ps is the name of your postscript file.
Errors in the file will result in no output, so check you file first with ghostview. To use this utility you must source the config file:
%source /local/config/cshrc.ghostview
and run a windowing system before it will work.
The quilts
Use the Postscript code to draw the quilts from the Postscript handout. Your ML program does not have to print this code (although it could), just the code to draw the composite quilt. This will be calls the Postscript procedures arcs and bands, plus the appropriate code to rotate and shift the basic quilts a and b.
What to hand in
Your ML source code, and one example of the Postscript code produced by you program, and the result as printed on a printer. Use the quilt on page 379 as you sample, although others are welcome as well. However, the quilt on page 379 is the minimum required.
Due date
Hand in your completed assignment on Tuesday, November 26th. before 5pm..