Assignment #1: Intro

Out: Tuesday, January 12th, Due: Monday, January 18th, 9:00pm



Administrative

The purpose of this assignment is to familiarize yourself with the various tools that will be used throughout the course, and to get a feeling of basic programming in Scheme. The main thing you need to know is the submission system that will not allow you to submit your code if it does not follow certain requirements. For example, you will not be able to submit code that doesn’t have the required definitions, or doesn’t bind them to appropriate value types, or code that contains lines that are longer than 79 characters. In addition, in this submission as well as future assignments, you are required to have tests that cover your whole code, or your submission will be rejected or severely penalized.

In this particular homework, the server will perform additional tests over your code, which will require you to come up with correct solutions to be able to submit. This means that you will generally be graded on contracts and purpose statements, other comments, style, test quality, etc. Correctness will play a very small here, since everyone is expected to be able to solve these questions.

The first thing you will need to do is to download and install PLT Scheme and then the course plugin. When this is done (and you restart DrScheme), you will be able to register for homework submission, as described in the Software Section. (If you work in the lab, PLT Scheme should already be installed.)
Shortly after you install the plugin and register, you will be added to the course mailing list, which will allow you to post the required test message (see below). Note: do not email requests to be subscribed to the mailing list, it will be done after you register with the handin server.

You might want to consult How to Design Programs and the Class Notes before writing your code.

For this problem set, you are required to set the language level to “Intermediate Student”. This will allow you to use the Stepper to debug your code, and more importantly: learn how Scheme evaluates it.

This homework is for individual work and submission.

Submitted code should have comments that describe the function and its type, as well as enough test cases for complete coverage (DrScheme indicates covered expressions with colors for covered and uncovered source code, unless your code is completely covered). Your tests should have the following form: (equal? <expected> <expression>).
Important: Your tests should cover your whole code, otherwise the server will heavily penalize your submission. You should not have any uncovered expressions after you hit “Run” — it should stay at the same color, indicating complete coverage. Furthermore, the server will run its own tests over your code, which means that you will not be able to submit code that does not work. Reminder: this means that most of the focus of this homework is put on the contract and purpose statements, good style (indentation, comments, etc), and good tests.

General note: do not duplicate code! If there is an expression that is used in multiple places, then you should use let.



Questions

  1. Post one test message to the course mailing list. Make sure that it actually appears, and contains your name (that is, your email address identifies you by name), otherwise you will not get the credit for posting. Reminder: the mailing list is http://groups.google.com/group/neu-pl/ (send mail to neu-pl@googlegroups.com), see also the Mailing List Section. Note that you will not be able to post on the mailing list until you are subscribed to it, and you will be subscribed to it only after you installed the course plugin and created an account — so make sure you do that first. Once you do this, you will get a notification when you’re on the mailing list.
  2. Problem 2.2.4 from Section 2.2 of How to Design Programs.
  3. Problem 4.4.3 from Section 4.4.
  4. Problem 5.1.3 from Section 5.1 and Problem 5.1.5. Use eq? to compare symbol values instead of equal? for tests in this case. (Note: you can (and should) use your solution to the previous question.)
  5. Remember that lists are defined inductively as either: A “Listof T” would be similar, except that it will use T instead of “any”.
    With this in mind, do Problem 9.5.4 from Section 9.5. Remember to write proper contract and purpose statement, and to have enough tests. (Note: you can assume a valid input list, as long as it’s documented in the contract header; no need for a ‘checked’ version, since you don’t have the tools to test errors yet.) Make sure your functions are called check-range1? and check-range? (with a “?” suffix).
    Since this is a boolean valued function, there is no need to use equal? in tests — you can simply use calls that should evaluate to true, and wrap not around calls that should evaluate to false.
    Hints: you can do this with or and and, no need for cond; also, <= can accept any number of arguments — (<= x y z) checks that x is smaller than or equal to y, and that y is smaller than or equal to z.
  6. Finally, implement a zip2 function that does the following: You can assume here too that the input is always valid.
    For example, here is a use of this function, in a test form (note that we’re now using equal? to compare a nested list structure):
    (equal? (list (list 1 'a) (list 2 'b) (list 3 'c)) (zip2 (list 1 2 3) (list 'a 'b 'c)))
    (This can be used as a test, and it will probably even cover your code completely, but you need more tests. Specifically, you need to test corner cases.)
    Make sure that you write a correct contract!
  7. In the definitions window, define my-picture — bind it to the number next to your picture in the pictures that were taken in class or the one from the university records. If you appear in several pictures, choose the one that looks best and/or the one you like most (please make sure that you are recognizable). You can also email us a good image of yourself in case you have a better one or if your picture is missing (but please use a picture that looks like you, no kindergarten pictures please).
    If your picture is not there, then please email one and wait for it to be added. As long as there is no picture, you can use 0, and say that you don’t appear there in a comment.
  8. Define minutes-spent as the number of minutes you spent on your homework. Please specify a reasonable estimate here and in future homeworks, since these values help in determining homework weights.