CS-257: Nonimperative Programming: Scheme!
Computer Science Department
University of New Mexico
Spring 2008

Instructor: Joel Castellanos
Office: Farris Engineering Center (FEC) 321
Office hours (Spring 2008):
     Monday & Wednesday: 11:00-noon,
     Tuesday: 8:00 - 9:15 AM
     and by appointment.
e-mail: joel@unm.edu


Course Description

In computer science, imperative programming is a programming paradigm that describes computation as statements that change the state of a program. The hardware implementation of almost all computers is imperative. From this low-level perspective, the program state is defined by the contents of memory, and the statements are instructions in the computer’s native machine language. Higher-level imperative languages, such as FORTRAN and C, use variables and more complex statements, but still follow the same paradigm. Object-oriented languages, such as C++ and Java, add support for objects to the imperative paradigm.

This course uses Scheme, a multi-paradigm programming language that is best known for its support of functional programming. Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable objects (objects that can be changed after being created). Functional programming emphasizes the application of functions, in contrast with the imperative programming style that emphasizes changes in state. Functional programming languages have largely been emphasized in academia rather than in commercial software development. However, notable functional programming languages used in industry and commercial applications include Erlang (concurrent applications), R (statistics), Mathematica (symbolic math), ML (analyzers, and theorem provers), K (financial analysis), and XSLT (Stylesheet to human readable).

This course is primarily a programming course. We will work through each chapter of the textbook in the order presented by the textbook. There will be weekly programming assignments, most of which will come from outside of the textbook. As fractals are so naturally expressed in functional languages, they will be a major application topic and source of assignments. Another area in which Scheme excels is Artificial Intelligence; thus AI games will form another major topic for programming assignments.




Textbooks

We will use two textbooks in this course plus some selected readings:
The Little Schemer - 4th Edition
by Daniel P. Friedman and Matthias Felleisen
Publisher: The MIT Press; 4 edition (December 21, 1995)

Foreword by Gerald J. Sussman:
The notion that "thinking about computing is one of the most exciting things the human mind can do" sets both The Little Schemer (formerly known as The Little LISPer) and its new companion volume, The Seasoned Schemer, apart from other books on LISP. The authors' enthusiasm for their subject is compelling as they present abstract concepts in a humorous and easy-to-grasp fashion. Together, these books will open new doors of thought to anyone who wants to find out what computing is really about.
The Little Schemer introduces computing as an extension of arithmetic and algebra -- things that everyone studies in grade school and high school. It introduces programs as recursive functions and briefly discusses the limits of what computers can do. The authors use the programming language Scheme, and interesting foods to illustrate these abstract ideas. The Seasoned Schemer informs the reader about additional dimensions of computing: functions as values, change of state, and exceptional cases.
The Little LISPer has been a popular introduction to LISP for many years. It had appeared in French and Japanese. The Little Schemer and The Seasoned Schemer are worthy successors and will prove equally popular as textbooks for Scheme courses as well as companion texts for any complete introductory course in Computer Science.

Scheme and the Art of Programming by George Springer and Daniel P. Friedman (MIT Press, 1989). You may purchase a copy of this at the UNM Copy Center which is located in Dane Smith Hall.

Godel, Escher, Bach: An Eternal Golden Braid by Douglas R. Hofstadter.
A Pulitzer Prize winning, metaphorical Fugue on Minds and Machines in the spirit of Lewis Carroll.

This is NOT a required textbook. There will, however, be some short selected readings from it placed on electronic reserve.



Class Notes

  1. Lecture notes from Friday, Jan, 25 2008
  2. Lecture notes from Monday, Jan, 28 2008
  3. Lecture notes from Wednesday, Jan, 30 2008
  4. Lecture notes from Friday, Feb, 1 2008
  5. Lecture notes from Monday, Feb, 4 2008
  6. Lecture notes from Wednesday, Feb, 6 2008
  7. Lecture notes from Monday, Feb, 11 2008
  8. Lecture notes from Wednesday, Feb, 13 2008
  9. Lecture notes from Friday, Feb, 15 2008
  10. Lecture notes from Wednesday, Feb, 20 2008
  11. Lecture notes from Monday, Feb, 25 2008

  12. Homework solution for Deterministic Context Free Language Checker
    • DCFL-checker: Scheme source for main function
    • applyFunctionToList? : Applies a given boolean function to each member of a given list. Returns true iff every result is true.
    • atom?: Standard Scheme atom test.
    • atomList?: Returns true iff the given list contains only atoms.
    • checkRangeOfReal?: Returns true iff a given real argument is within a given range.
    • extractUniqueAtoms: Recurses through all levels of a given list and returns a list of atoms consisting of all unique atoms present at any level of the original list.
    • getFirstAtomOfEach: Given a list of lists, this function returns a list composed of the first element of each list in the Given a list of lists.
    • listofuniqueatoms?: Returns #t iff a given list a list of atoms, and none of the atoms are repeated.
    • rember : Standard Scheme remove member function. This removes the first occurance of a given atom from a given list.
    • removeListfromList: Removes the first occurance of each item in a given list from a given list.
    • test: Displays a given error message if the two given objects are not identical. This function is used for unit testing
  13. Lecture notes from Monday, March, 3 2008
  14. roulette.scm:Homework solution for Winning at Roulette - or not
  15. Homework solution for Scheme and the Art of Programming Chapter 4
  16. Lecture notes from Friday, March, 7 2008
  17. Homework solution for Scheme and the Art of Programming Chapter 5
    • Exercise 5.3: Scope of arguments in let, letrec, and converting let to lambda.
    • Exercise 5.10: Polynomal functions: degree, leading-coef, rest-of-poly, zero-poly?, and poly-cons.
    • Exercise 5.10: Rework of the textbooks polynomal addition function where only temperary variables that are used are defined.
  18. Lecture notes from Wednesday, March, 12 2008
  19. Lecture notes from Wednesday, March, 26 2008
    • lines.scm: Program using Mr Ed that creates a frame, and draws an X to the inside corners of the frame. The size of the X updates when the frame is resized.
    • drawSystem.scm: Solution to Homework 8. Draws simple l-system consisting of an arbitrary list of +, -, and f where + and - are always right and left turns of 90 degrees and f is always a straight line of 20 pixels. The state of the turtle is updated with the use of (set! <var> <exp>).
    • drawsystem-no_set.scm: A variation of drawSystem.scm where all uses of (set! <var> <exp>) have been removed. Functions which in drawSystem.scm update the state of the turtle, in drawsystem-no_set.scm take the turtle state as an argument and return a list that consists of the updated turtle state. Both drawSystem.scm and drawsystem-no_set.scm have exactly the same number of recursive calls.
  20. Lecture notes from Friday, March, 28 2008
  21. L-System Project
  22. Scheme Vectors, An application of vectors in the Chaos Game, and the use of vectors to make a matrix.
  23. [updated 5/7]
  24. ChaosGame.scm Example of using vectors: Draws Sierpinski Triangle and other fractals using the Chaos Game. Takes one argument with is a vector of the verticies of a polygon inside a unit square.
  25. Light Cycle Project.[updated 5/7]
  26. Sample Questions of the type to be expected on the final exam. [added 5/11]


On-line Documentation:

  1. R5RS: There are two standards that define the Scheme language: the official IEEE standard, and a de facto standard called the Revisedn Report on the Algorithmic Language Scheme, abbreviated RnRS, where n is the number of the revision. The current standard is R6RS ratified on August 28th, 2007. However, this course uses the more universaly supported R5RS.
  2. Teach Yourself Scheme in Fixnum Days by Dorai Sitaram. This is a brief Scheme tutorial for people who are already familiar with programming.
  3. The Scheme Programming Language: ANSI Scheme by R. Kent Dybvig, (2nd Edition, Prentice Hall, 1996). The entire text is on-line.
  4. The Schematics Cookbook Scheme recipes for common tasks in practical contexts — a collaborative effort from Schematics.



Scheme Implementation

This course uses the open source Scheme implementation MzScheme (pronounced "Ms. Scheme"). MzScheme is mostly R5RS-compliant, and provides several notable extensions. The download site contains documentation and executables for Linux, Windows, and Mac. The Linux version is installed in the CS lab in FEC 307, and can be found under Apps -> Programming -> MzScheme.

The course will also uses DrScheme, an interactive, integrated, graphical programming environment for MzScheme.


Grading


Attendance

Your attendance at lectures and recitation section meetings is mandatory. Attendance will be taken in recitation. If you miss more than three recitation section meetings, then you will be given a failing grade (F) for the course. Due to the large class size, it is not practical to take attendance at each lecture. However, quizzes will be in-class and unannounced. There are no make-up quizzes regardless of the reason for missing class. If you have a major automobile accident, it may not be your fault, but you should expect that it will interfere with your education (it may also interfere with your ability to walk and breath). There will be 10 to 20 quizzes, so missing one will impact your grade by at most 2 percent, and probably closer to 1%.

If you play on a UNM sports team that requires travel this semester, then you must give me your game and travel schedule early in the semester.



This great tune by Bob Kanefsky was bequeathed to me in its mp3 form by my friend and colleague Lance Williams: God Wrote In Lisp (mp3).