CS 476/MCS 415: Programming Language Design

Spring 2007

Homework 2: Sorting in Lisp

Due: Friday March 23, 2007 at 11:59 pm (i.e. before spring break starts)

For this assignment, you are to implement a number of common sorting algorithms in Lisp. The primary purpose of this assignment is to use these common algorithms to get you think in Lisp. Simply going out on the Internet and finding the solutions won't help you to think in Lisp. So please don't do that. You may work in groups of two on this assignment. Hopefully, each of you will help the other to think in Lisp.

You are to write the functions using the names specified:

Each function should require a single input argument, which is a list of numbers. You can assume there are only numbers in the input list, i.e., no error checking is required. The output should be a list containing the same numbers, sorted in ascending order.

Lisp works best when there are a number of small functions that are used together to solve the problem instead of trying to write one big function. For example, when writing selection sort, we may want one function that will find the smallest value in a list and another function to remove the smallest value in a list (or to remove a specific value from a list). Using these functions, a recursive call to selectsort and a list joining function should be sufficient to write the selection sort algorithm in lisp.

Don't forget to put comments in your code.

Try to make your code as purely functional as possible. In particular, avoid defining variables (e.g., "setf" and "setq"), and avoid iteration ("do"). Use functions instead of variables, and recursion instead of iteration.

What and how to submit

You are to submit your code electronically via turnin on the CS machines using the name of hw2. You are to submit two files: You will submit your files using the turnin command on the CS server:
     turnin -c cs476 -p hw2 hw2.lisp  README

You may work on this project by yourself or in a group of two. If you work on this with another member of the class, only submit your project once using turnin. Be sure that you clearly state in your README file the names and NETIDs of both members in the group.