Blame


1 12687dd9 2023-08-04 jrmu ;; The first three lines of this file were inserted by DrScheme. They record metadata
2 12687dd9 2023-08-04 jrmu ;; about the language level of this file in a form that our tools can easily process.
3 12687dd9 2023-08-04 jrmu #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 12687dd9 2023-08-04 jrmu ;A traffic-light color (TL-color) is either
5 12687dd9 2023-08-04 jrmu ;1. 'red,
6 12687dd9 2023-08-04 jrmu ;2. 'yellow, or
7 12687dd9 2023-08-04 jrmu ;3. 'green.
8 12687dd9 2023-08-04 jrmu
9 12687dd9 2023-08-04 jrmu ;;State Variable:
10 12687dd9 2023-08-04 jrmu ;;current-color : TL-color
11 12687dd9 2023-08-04 jrmu (define current-color 'red)
12 12687dd9 2023-08-04 jrmu
13 12687dd9 2023-08-04 jrmu ;next : -> void
14 12687dd9 2023-08-04 jrmu ;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.
15 12687dd9 2023-08-04 jrmu
16 12687dd9 2023-08-04 jrmu (define (next)
17 12687dd9 2023-08-04 jrmu (set! (next-color current-color)))
18 12687dd9 2023-08-04 jrmu
19 12687dd9 2023-08-04 jrmu ;next-color : TL-color -> TL-color
20 12687dd9 2023-08-04 jrmu ;Given acolor, returns the next logical color.
21 12687dd9 2023-08-04 jrmu
22 12687dd9 2023-08-04 jrmu (define (next-color acolor)
23 12687dd9 2023-08-04 jrmu (cond
24 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'red) 'green]
25 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'yellow) 'red]
26 12687dd9 2023-08-04 jrmu [(symbol=? acolor 'green) 'yellow]))