Lab 3: Lists of Numbers, File I/O
Beginning Student with List Abbreviations
cs105_io.ss
The primary goal of this week's exercise is for you to gain experience writing functions that consume lists of numbers. This afternoon, you will write functions to compute some common statistical measures of a dataset, such as the mean, variance and standard deviation. A secondary goal is to show you how to read text files from within the DrScheme environment. Loading and saving of files is known as I/O, for Input/Output. Using I/O, you will use your statistics functions to process (relatively) large datasets: namely, historical data about Major League Baseball players.


Preliminaries

Download the following three files onto your desktop.

This cs105_io.ss teachpack provides two functions:

;; read-from-file: string -> list-of-num
;; write-to-file: list-of-num string -> string
The function read-from-file takes one argument: a string which is the name of a data file. That file is read into a list of number, one number at a time.

We will not use the function write-to-file this afternoon; it works similarly.

Your Assignment

Part I

At the top of the definitions window, provide a data definition for num-list.

Write Scheme definitions for count (which should give the number of elements in a list), sum, mean, variance and stdev (standard deviation). Provide contracts, purposes and test cases for each.

There are different ways of defining variance and standard deviation in the realm of statistics. For this lab, please adhere to the following definitions.

Part II

Once all of your functions are working properly, use them, together with the read-from-file teachpack function, to analyze the given baseball data. Your results should correspond to the numbers in the Benchmarks section below.

You will need to feed full pathnames to read-from-file when you call it. The full pathnames of the data files on your desktops will be of the form

/nfs/harper/hc1/your-username/Desktop/W50s.txt

Extra Credit

Write median.

Benchmarks

To make sure your numbers are not way off base, here are a few ballpark figures to check against your results:

Hand in your work.

Submit your work to Chalk according to the following instructions.