UW-Madison
Computer Sciences Dept.

CS739 Spring 2009: Programming Assignment 2 -- Sequential Erlang

Due: Thursday, February 12th at the start of class
Reading: Chapter 3 of Programming Erlang

You are again welcome to work with others for this assignment, but each person must turn in their own code.

Overview

The goal of this assignment is to make sure we all understand how to do basic sequential programming in Erlang. We'll compile Erlang code this time, define records, and see that you can create your own new functions for processing items in a list.

This assignment will only require a very few lines of Erlang code, but it can be a little frustrating if you are learning a functional language for the first time. It requires no reading beyond Chapter 3.

Experimental Platform

You will again use the Erlang shell (available from /s/erlang/bin/erl). You will also define a record and functions in a file "courses.erl". You can compile your code from within the shell with the command c(courses).

N Simple Steps

We'll be modifying the course list you developed for Assignment 1. There are two changes. First, this time, each course in the list should be a properly defined Record (instead of nested tuples). Second, you will write functions to process the list counting the number of times each instructor was listed. For example, if the input is

[{course,"Distributed Systems",739,"Swift",2010},
 {course,"Distributed Systems",739,"A. Arpaci-Dusseau",2009},
 {course,"Distributed Systems",739,"A. Arpaci-Dusseau",2008},
 {course,"Distributed Systems",739,"Miller",2007},
]
your output list should be [{"A. Arpaci-Dusseau", 2}, {"Swift", 1}, {"Miller", 1}]
  1. Define an Erlang record, "course". As before, a course should have fields for the name of the course (e.g., Distributed Systems), its number (e.g., 739), its instructor (e.g., Arpaci-Dusseau), and the year (e.g, 2009).
  2. Define a function make_list that returns a list of at least 5 courses with an "interesting" set of instructors.
  3. Define a function count that takes a course list and returns a list of the instructor names and counts as described above. Your function should work for arbitrary course lists: you shouldn't make any assumptions about the instructor names or the length of the course list.

    You are free to use any Erlang functions you want to accomplish this. You may find various Erlang list functions (e.g., map, filter, usort, and last) useful. But, maybe not.

  4. Comment your code enough that someone can follow what you did.

Turning in your assignment

Please bring to class a print out of your commented file, course.erl. Also, turn in a shell session again where you show your functions in action. Show that you can correctly count instructors in three different lists (e.g., try different lengths).

We won't grade you on elegance, or simplicity, or creativity, or anything other than functionality and comments. If different students come up with wildly different solutions, we'll try to share some of the different approaches.