Scheme 1

Cover page image

Cay S. Horstmann

Why Scheme?

Scheme Features

Control Flow

Anonymous Functions



List Functions

Why This Isn't Inefficient



Step 1

  1. Install Racket from (Racket is a Scheme dialect with a pretty nice environment.)
  2. Start the interactive Dr. Racket console by launching drracket or drracket.exe.
  3. Work through steps 2 and 3 of (which is also inside the doc/quick directory of your Racket installation)
  4. As instructed, try the F1 key. How do you get the circle and square aligned at the top?

Step 2

  1. Implement a function circles so that (circles n) draws a row of n circles, like this: oooooooooo

    Hint: (hc-append (circle 10) (circles ...))

  2. Work through step 5 of the tutorial.

    How can you tell that the nested define binding in the first part of step 5 is really local?

  3. What happens when you use let instead of let* in the last part of step 5? Why?

Step 3

  1. Work through step 6 of the tutorial. Then improve on the series function so that it can make a series of arbitrary sizes, i.e.
    (series circle '(5 10 20))

    has the same effect as the original version, but we can also do

    (series circle '(5 10 20 10 5))

    What is the code of your function?

  2. Work through step 7. The text makes a big deal out of the fact that the λ expression is “lexically scoped”. What term do we normally use to describe such a function?
  3. Work through step 8. Look at the nifty list that you get from (rainbow (square 5)). Look carefully—it's a quoted list of shapes, not a painted shape. How do you change series so that you get a list of shapes instead of a combined shape?
  4. Having a list is so much more useful. You can now make a vertical drawing of them, with one line of code. How?