Blob


1 ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 ;; about the language level of this file in a form that our tools can easily process.
3 #reader(lib "htdp-advanced-reader.ss" "lang")((modname |36.4|) (read-case-sensitive #t) (teachpacks ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp"))) (htdp-settings #(#t constructor repeating-decimal #t #t none #f ((lib "draw.ss" "teachpack" "htdp") (lib "arrow.ss" "teachpack" "htdp") (lib "gui.ss" "teachpack" "htdp")))))
4 ;A traffic-light color (TL-color) is either
5 ;1. 'red,
6 ;2. 'yellow, or
7 ;3. 'green.
9 ;;State Variable:
10 ;;current-color : TL-color
11 (define current-color 'red)
13 ;next : -> void
14 ;Effect: Changes current-color from 'red to 'green, 'green to 'yellow, or 'yellow to 'red depending on what the current-color is. Produces no output.
16 (define (next)
17 (set! (next-color current-color)))
19 ;next-color : TL-color -> TL-color
20 ;Given acolor, returns the next logical color.
22 (define (next-color acolor)
23 (cond
24 [(symbol=? acolor 'red) 'green]
25 [(symbol=? acolor 'yellow) 'red]
26 [(symbol=? acolor 'green) 'yellow]))