CS 30 Homework 4

Due by the beginning of class Tuesday, October 1
  1. Reading assignment: Chapters 1-2 of Concrete Abstractions. These chapters should be mostly review for you at this point. Section 3.3 of Chapter 3 (pages 58-61) discusses let expressions, so that might also be good to look at. It also introduces internal definitions, which we haven't talked about yet.

  2. Finish parts 5-8 of this week's lab. You can find sample solutions to parts 2-4 in the CS 30 class folder under Lectures/week04/lab4-solutions.scm. Specifically, write the functions lookup, covered?, and evaluate, and rewrite value as described in part 6. Remember to test your functions thoroughly on several different arithmetic expressions.

  3. Rewrite the function seconds from the first homework in terms of map, without using cond or if. Examples:
    (seconds '((paella spanish) (wine red) (and beans))) => (spanish red beans)
    (seconds '((red hot) (chili dogs))) => (hot dogs)

  4. Write the function remove-negs in terms of filter, without using cond or if. The definition of filter can be found in the notes from today's lecture (Lectures/week04/examples.scm). Remove-negs takes a list of numbers and removes all of the negative numbers from the list. Examples:
    (remove-negs '(-3 -2 -1 0 1 2 3)) => (0 1 2 3)
    (remove-negs '(7 -3 4 -1 -6)) => (7 4)

  5. The class folder also contains the database functions that we developed in class (Lectures/week04/database.scm). Study this code until you understand how it works. Then do the following problems, using database.scm as your starting point.

    IMPORTANT: You are not allowed to use the functions car or cdr in your definitions of retrieve-age, where-is, or send-cards. Instead, you should access information in the database only via retrieve-info, find-entry, and find-all.

EXTRA CREDIT

Do not work on the extra credit until you have finished the above problems.

If you're itching for some more fun Scheme problems, do as many of the following exercises as you wish from the Concrete Abstractions book: Exercises 1.8 through 1.11 in Section 1.3 (pages 15-18) and 2.13 through 2.15 in Section 2.4 (pages 40-42). All of these problems involve constructing visual "quilt patterns". If you have trouble picturing the various turning and stacking operations in your head, you may find this page helpful.

In order to be able to use the graphical operations described in the book, you will have to first load a predefined Scheme file into your Scheme system, as explained below. I would recommend using DrScheme. Chez Scheme pops up a separate window for each new image you create, which quickly gets to be annoying.

DrScheme
  1. Download the file graphics-dr.ss to your computer. You can put this file anywhere you like on your hard drive (a good place might be in the folder C:\Program Files\PLT\teachpack), but you shouldn't move it after it is installed.
  2. Start DrScheme, choose Language -> Add Teachpack, browse to wherever you stored the graphics-dr.ss file, select it, click Open, then click the Execute button. From now on when you start DrScheme, the graphics-dr.ss teachpack file should load automatically.
Chez Scheme/SWL
  1. Download the file graphics-swl.ss to your computer. You can put this file anywhere you like on your hard drive.
  2. To use the graphics functions, you will have to manually load graphics-swl.ss whenever you start Chez Scheme. Choose File -> Load, browse to wherever you stored the graphics-swl.ss file, select it, and click Open. If you put the file in C:\Program Files\Chez Scheme\csv6.0a\swllib\tutorial, you should be able to just type (load "graphics-swl.ss") at the Scheme prompt to load the file.

Turning in your homework

Put all of your definitions into a single file called hw4.scm. Bring a hardcopy printout of the file with you when you come to class on Tuesday. In addition, copy this file to your Userspace before coming to class. I'll show you how to submit it electronically next week.