Assignment #1: IntroOut: Friday, January 18th Due: Tuesday, January 22nd, 8: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. For this submission (as well as most future
assignments), you are also required to have tests that cover your whole
code, or your submission will be rejected.
The first thing you will need to do is to download and install the
course plugin, and 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).
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 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 (which DrScheme
indicates in green color, unless your code is completely covered). Your
tests should have the following form: (= <expected> <expression>).
Important: Your tests should cover your whole code, otherwise the
server will reject your submission. You should not have any red parts
when 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. 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.
Questions
- Post one test message to the course mailing list. Make sure that it
actually appears, and contains your name (that is, your email address
contains your name and not some obscure nickname), otherwise you will not
get the credit for posting. Reminder: the mailing list is http://groups.google.com/group/csu660/ (send mail to csu660@googlegroups.com), see also
the Mailing List Section. Important: you will not be able
to post on the mailing list until you are subscribed to it, and you will be
subscribed to it after you installed the course plugin and created an
account — so make sure you do that soon.
- Problem 2.2.3 from Section 2.2 of How to Design Programs and Problem 2.3.3 from Section 2.3.
- Problem 4.4.1 from Section 4.4 and Problem 4.4.4. (Note: do not
duplicate code! If there is an expression that is used in multiple
places, then you should use let.)
- Problem 5.1.4 from Section 5.1. Use eq? to compare symbol values instead
of = for tests in this case. (Note: you can (and should) use your
solution to the previous question.)
- Remember that lists are defined inductively as either:
- An empty list — null
- A cons pair (sometimes called a “cons cell”) of any
head value and a list as its tail — (cons x y)
A “Listof T” would be similar, except that it will use T
instead of “Any”.
With this in mind, do Problem 9.5.7 from Section 9.5. Remember to write proper
contract and purpose statement, and to have enough tests. (Note: you can
assume a non-null input list, as long as it's documented in the
definition header; no need for a ‘checked’ version, since you don't
have the tools to test errors yet.)
- Optional bonus (+10): make average-price tail-recursive, and
avoid a double-pass on the input list (ie, don't use length). (If
you do this, then don't write a second definition of average-price,
just make the above solution tail recursive, and indicate this fact in a
comment.)
- Finally, implement a zip2 function that does the following:
- It consumes two arguments that are lists of equal length, say
(Listof A) and (Listof B) for some types A and B.
(Note that you cannot express the fact that they are equal-length
lists with the way we write contracts, so make sure you mention that
in the purpose statement.)
- The result is a list that contain two-element lists from the
first and the second lists respectively. Use (list ? ?)
to specify a two-item list in your contract.
For example, here are some uses 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))) |
(Note that 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!
- In the definitions window, define a my-picture variable. It
should be bound to the number next to your picture in the
pictures that were taken in class. If you see
several pictures, choose the one you like most. You can also send me a
good image of yourself in case you have a better one or if you did not
come to class (but use a picture that looks like you, no kindergarten
pictures please).
- In the definitions window, define a minutes-spent variable.
This variable should be bound to the number of minutes you spent on your
homework.