#1#
This is a preliminary draft of the book. The final book will appear with MIT Press in 2001 and will move to its permanent Web site sometime in the fall of 2000.
#2#
The Design Recipe for Functions
Problem Analysis & Data Definition
Contract, Purpose & Effect Statements, Header
Examples
Functiona Template
Function Definition
Tests
#3#
The dependence graph has to be translated into an HTML-suitable format.
#4#
This marker refers to teacher hints, which suggest strategies on how to present a section, on how to approach an exercise, or on how to supplement some material.
This marker refers to DrScheme hints. The programming environment has been designed with students in mind. The hints suggest how to use it at various stages of the learning process.
This marker, placed at the end of exercises, links to on-line solutions. Solutions are available to registered teachers. To find out more about registration, see the book's registration site (not available yet).
#5#
#6#
#7#

#8#

#9#
#10#

#11#

#12#
[planets in DrScheme]
#13#
 ;; dimensions of traffic light (define WIDTH 50) (define HEIGHT 160) (define BULB-RADIUS 20) (define BULB-DISTANCE 10) ;; the positions of the bulbs  (define X-BULBS (quotient WIDTH 2)) (define Y-RED (+ BULB-DISTANCE BULB-RADIUS)) (define Y-YELLOW (+ Y-RED BULB-DISTANCE (* 2 BULB-RADIUS))) (define Y-GREEN (+ Y-YELLOW BULB-DISTANCE (* 2 BULB-RADIUS))) ;; draw the light with the red bulb turned on (start WIDTH HEIGHT) (draw-solid-disk (make-posn X-BULBS Y-RED) BULB-RADIUS RED) (draw-circle (make-posn X-BULBS Y-YELLOW) BULB-RADIUS YELLOW) (draw-circle (make-posn X-BULBS Y-GREEN) BULB-RADIUS GREEN) 
#14#
#15#
#16#
#17#

#18#

#19#
(cons 'Mercury empty)
'Mercury empty
(cons 'Venus (cons 'Mercury empty))
'Venus
'Mercury empty
(cons 'Earth (cons 'Venus (cons 'Mercury empty)))
'Earth
'Venus
'Mercury empty
#20#
Item Price Image
robot 29.95
robot 29.95
robot 29.95
#21#
#22#
#23#

#24#

#25#
Tree A: Tree B:
[bst] [bst]
#26#

Scheme expression representation of Scheme expression
3 3
x 'x
(* 3 10) (make-mul 3 10)
(+ (* 3 3) (* 4 4))(make-add (make-mul 3 3) (make-mul 4 4))
(+ (* x x) (* y y))(make-add (make-mul 'x 'x) (make-mul 'y 'y))
(* 1/2 (* 3 3)) (make-mul 1/2 (make-mul 3 3))

#27#
#28#

#29#

#30#
(listof number)->(listof number)
(listof IR) ->(listof symbol)
#31#
(number -> number) (listof number)->(listof number)
(IR -> symbol) (listof IR) ->(listof symbol)
#32#
number (listof number)->(listof number)
number (listof IR) ->(listof IR)
#33#
(number number -> boolean) number (listof number)->(listof number)
(number IR -> boolean) number (listof IR) ->(listof IR)
#34#
(number X -> boolean) number (listof X)->(listof X)
(number X -> boolean) number (listof X)->(listof X)
#35#
#36#

#37#

#38#
lunar
#39#
#40#
#41#
#42#

#43#

#44#
(list 11 8 14 7)
(list 8 7)
(list 7)
empty 7
empty
(list 7)
8
empty
(list 7 8)
11
(list 14)
empty 14
empty
(list 14)
(list 7 8 11 14)
#45#
list to be sorted
sort process for partition with items smaller than pivot pivot item
sort process for partition with items larger than pivot
sorted list
#46#
#47#
#48#
#49#
#50#
#51# #52#
#53#
#54#
#55#
#56#
#57#
#58#
#59#
[An intersection]
#60#
[A Rice University Tour in DrScheme]
#61#
[A Rice University Tour in DrScheme]
#62#
[Multiple Traffic Lights]
#63#
[cards in DrScheme]
#64#
(define hand0 (create-hand 13 spades))
rank suit next
13 spades empty
(add-at-end! diamonds 1 hand0)
rank suit next
13 spades
rank suit next
13 diamonds empty
#65# [in-place sort] #66#
  i-1  
  a  
left   right
#67#

a vector fragment with pivot item p:

left   right
p sm-1 la-1 sm-2 sm-3 la-2



partitioning the vector fragment into two regions, separated by p

left1   right1   left2 right2
sm-2 sm-1 sm-3 p la-1 la-2
#68#

finding the swapping points for partition:
left right
p sm-1 la-1 sm-2 sm-3 la-2
new-left new-right



swapping the items and recuring on a new interval:

  left   right
p sm-1 sm-3 sm-2 la-1 la-2



stopping the generative recursion and clean-up:

  left   right
p sm-1 sm-3 sm-2 la-1 la-2
  new-right new-left
#69#
bidirectional family trees